SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
-
Apr 21, 2001, 14:31 #1
- Join Date
- Apr 2001
- Location
- San Francisco Bay Area
- Posts
- 6
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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++;
}
}
//-->
</script>
<body onunload="onul()">
-
Apr 21, 2001, 17:49 #2
- Join Date
- Aug 1999
- Location
- East Lansing, MI USA
- Posts
- 12,937
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
history.back(-2);
Chris Beasley - I publish content and ecommerce sites.
Featured Article: Free Comprehensive SEO Guide
My Guide to Building a Successful Website
My Blog|My Webmaster Forums
-
Apr 21, 2001, 22:18 #3
- Join Date
- Apr 2001
- Location
- San Francisco Bay Area
- Posts
- 6
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
history.back(-2); ----- Goes Where?
Being a bit of a newbie to Javascript I'm not sure quite where to place:
history.back(-2);
Thanks
-
Apr 21, 2001, 22:28 #4
- Join Date
- Jul 1999
- Location
- Chicago
- Posts
- 2,629
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
First of all, to go back it would be history.back(2); or history.go(-2) (which is what I think you, aspen, were thinking of).
Here is how the code should look, if I understand you correctly.
<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) history.go(-2);
times++;
}
}
//-->
</script>
<body onunload="onul()">
This will make it so if you click "No" on the message box, it will take you back two pages. If you click yes, it will close the page.
-
Apr 22, 2001, 11:19 #5
- Join Date
- Jul 1999
- Location
- Chicago
- Posts
- 2,629
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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++;
}
}
//-->
</script>
<body onbeforeunload="onul()">
-
Apr 22, 2001, 11:46 #6
- Join Date
- Apr 2001
- Location
- San Francisco Bay Area
- Posts
- 6
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Quinn -
Thanks for your help, unfortunately that didn't help. I tried both -2 and -3. Can you suggest a *Plan B*?
RonBo
-
Apr 22, 2001, 11:50 #7
- Join Date
- Jul 1999
- Location
- Chicago
- Posts
- 2,629
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sure...tell me if this would do what you want.
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...
-
Apr 22, 2001, 12:26 #8
- Join Date
- Apr 2001
- Location
- San Francisco Bay Area
- Posts
- 6
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I believe what your talking about is putting in an additional link on my main page that would act as a back button...yes?
I had considered that and if I could figure out how to get my previous post to work (Dynamic Menu Bar - I.E. only?) in Netscape that would be great. http://www.sitepointforums.com/showt...threadid=21483
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
Thanks again for your time and effort.
Ron
Bookmarks