I would like to adapt this script to go back 2 pages, as I'm trying to bypass a browser redirection page which has disabled my Back button. Yeah...I tried to contact Nicolas at javascript-page.com but as of yet he is non-responsive. Any help?
<script language="Javascript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com
var your_message = "Do you really want to leave this page?";
var times = 0;
function onul() {
if (times == 0) {
var leave = confirm(your_message);
if (!leave) location = self.location;
times++;
}
}
In your PM, I think I found out what the problem was.
OnUnload is triggered AFTER the browser window has been closed. So the history. commands won't work anymore.
The fix is somewhat simple. Instead of OnUnload in your <body> tag, use OnBeforeUnload. This is somewhat newer, but it is the only way to do what you want.
Now, when you close the window, before it actually disappears, you will see the alert box.
History.go(-2) should work, but if the page back two pages IS the redirect page, then use -3.
This code works for me in Mozilla 0.81--it should also work in IE. If it doesn't, then it'll be a little more complicated...
<script language="Javascript">
<!--
// please keep these lines on when you copy the source
// made by: Nicolas - http://www.javascript-page.com
var your_message = "Do you really want to leave this page?";
var times = 0;
function onul() {
if (times == 0) {
var leave = confirm(your_message);
if (!leave) { location = self.location; history.go(-2); }
times++;
}
}
Instead of that bit of Javascript, put a link to javascript:history.go(-2) (instead of http://something) and tell people that's where they should click on that link if they want to continue. Does that help at all? If not, I have a few more ideas...
Basically my site is set up as a self-paced tutorial and I am trying to *encourage* people to just click one main link (Freedom). So the fewer links I can show the better. If I could ever get the Dynamic Menu Bar, which floats on the page, to work in Netscape I would like to just have the Freedom link and the floating menu bar showing.
If I haven't made myself clear maybe checking out my main page would help: http://www.rbcplanet.com
Bookmarks