Forum Moderators: open
Hi,
First post on this board. Very nice forum :)
I'm trying to detect when the user clicks the [Back] or [Forward] button in their browser. Supposedly onBack and onForward can do that. However, the following code was unsuccessful on WinXP/IE6 + NS7.1:
<body onBack="alert('user pressed back');">
Also, tried placing the event inside <html>, <head>, and <script></script> to no effect. How/where should I use these handlers?
Furthermore, I need to detect the URL (complete with #hash) the user will be taken to. I have DIVs that are shown/hidden via JS based on the #hash. It'd be nice to be able to call the function on Back/Forward events to make navigation more intuitive for the user.
Thanks!
Here's a page demonstrating my problem -- [oxigen.f2o.org...]
Click on "Tidal Wave", "Decoy", "Pure Water", etc. Now, click [Back] and [Forward]. Do not click "< Virtue's Disciple" or "Dragon Knight >"; those leave the page.
You'll see the page simply stays in the last state when you clicked an internal link. However, the URL bar changes between ...#s1 ...#s2 ...#s3 and so on. What I'm trying to do is to update which DIVs are displayed when [Back] and [Forward] are used, same as when clicking the links inside the page. This can be easily done, if I could simply detect the full content of the URL bar after [Back] or [Forward] is pressed.
On a straight HTML doc, with straight #anchors, [Back] and [Forward] work as you'd expect. The page will scroll to the referred #anchor. However, I'm using #anchors as markers for processing by JS. DIVs on the same page are hidden and shown based on the #hash.
Hope that clears it up a bit more. Thanks for taking a look :)
"2.10: Can I detect the back button?
Unfortunately, no! However, the event handlers onBack and onForward are planned in a later version of Communicator."
A search for "onBack" on the current devedge.netscape.com site returned no results. Does this mean support was never implemented, and never will be? Thus, all references to onBack and onForward are invalid? So, there is no solution to my problem?
Sorry for bothering you all so much about this. It's the last major bug I need to squish =/
Right now, I'm beginning to think it's necessary to have a looping timer set to 1 second intervals simply to detect if the URL#anchor has changed. Very messy and inefficient, but the only supported solution so far =/