zattz
asked on
Show alert when back button is pressed
Hi all,
how can I show a message box when the back button is pressed?
Thanks
how can I show a message box when the back button is pressed?
Thanks
Don't you mean window.onunload?
Although, even clicking a link or going forward will make the event fire.
Although, even clicking a link or going forward will make the event fire.
ASKER
Dosn't work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> .. show a message box when the back button is pressed?
impossible (except patching the browser)
impossible (except patching the browser)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
window.onunload() does not work if you navigate with the browser's back button from http://..../this#that to http://..../this
Hence this is not a working answer if you read the question verbatim.
Just my 2 pence ...
Hence this is not a working answer if you read the question verbatim.
Just my 2 pence ...
Hehe, yep... it's really not the fix for that. In fact, onunload is a very unreliable way to detect back navigations, I admit.
If you want to detect back navigations from this.htm#that to this.htm, I'd put a timer that checks window.location.hash -- I believe this method is being used by a few Flash-based websites to detect back button clicks.
If you want to detect back navigations from this.htm#that to this.htm, I'd put a timer that checks window.location.hash -- I believe this method is being used by a few Flash-based websites to detect back button clicks.
ASKER
Hmm..
that window.location.hash is interesting,
but anyway the onunload is good enough for the page I want it on.
thanks guys
that window.location.hash is interesting,
but anyway the onunload is good enough for the page I want it on.
thanks guys
window.close = function(){alert("your message");}
</script>