...

View Full Version : history.go(-1) what if there ISNT any 1 to go to?



matthewb
01-19-2003, 04:12 AM
Hiya. In need of a little help on a kind of go back one page OR do something else function. If that makes any sense...

At the moment I have:

{
alert("Site Closed.\nClick OK to return.");
history.go(-1);
}

The problem is if the page is the first that the person has visited (they went there directly) then there is no -1 to send them to. So Id like something that works along the lines of:

if no -1 page exists then parent.close()

But Im entirely unsure if and how you can find out that there is no -1 page and how youd then trigger the window close event instead.

Any help would be most appreciated.

Cheers :)

Matthew

PS: If you could make it thicky-proof that'd be even more helpful :p

jkd
01-19-2003, 04:37 AM
(history.length ? history.back : top.close)();

matthewb
01-19-2003, 02:11 PM
Thank you. Fabulous. Does it exactly and perfectly :) Yay!

However, I'm now getting a bit carried away by the joy of all this JavaScript stuff...

Thanks to jkd I now have:

{
alert("Site Closed.\nClick OK to return.");
history.go(-1);
(history.length ? history.back : top.close)();
}

Suppose I wanted to do something other than close window? Maybe flash the background colour of the page to a bright red alert colour... I found this script somewhere; who only knows where now... but say I wanted to use this instead. How would I 'join' this to the 'no history' bit?

{
intrvl=0;
for(nTimes=0;nTimes<3;nTimes++){
intrvl += 200;
setTimeout("document.bgColor='#FF0000';",intrvl);
intrvl += 4000;
setTimeout("document.bgColor='#FFFFFF';",intrvl);
}

This is idle curiosity now. I don't really have any need for it; but since someone probably knows, and it's vageuly interesting (to me) I though I'd ask.

Cheers again,

Matthew :D

Algorithm
01-19-2003, 10:35 PM
{
alert("Site Closed.\nClick OK to return.");
if(history.length){
history.back();
} else {
intrvl=0;
for(nTimes=0;nTimes<3;nTimes++){
intrvl += 200;
setTimeout("document.bgColor='#FF0000';",intrvl);
intrvl += 4000;
setTimeout("document.bgColor='#FFFFFF';",intrvl);
}
}
}

matthewb
01-19-2003, 11:23 PM
Hurrah for www.codingforums.com!

Thanks guys. Most groovy.

Matthew



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum