Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
-5
rated 0 times [  0] [ 5]  / answers: 1 / hits: 52308  / 13 Years ago, mon, november 21, 2011, 12:00:00

I want to alert() when browser's back or forward button is clicked or hash is changed in javascript. I have tried this solution and it is working but it is causing problems on other links in webpage and submit each request twice on any link click event.



Is there any solution to capture it without using setInterval() function? So I need to capture hash change or back/forward button click event? I need a simple javascript code/function/property that should work in all modern browsers.



Any solution ?



Thanks


More From » browser

 Answers
56

Not a good idea



Can you rather explain the reasoning behind this? We've all been down this road of preventing backs/forwards and similar and mangling with browser functionality.



It turns out though it's better to obey to browser and write your application in that way so these things become irrelevant. And it's also true that browsers are locking more and more things to client javascript apps so it's highly likely your app is going to fail after (few) browser upgrades.



Go with HTML5



HTML5 History spec may be exactly what you're after. It's the way things should work and be done in regard to Ajax applications and browser0s back/forward functionality. I suggest you check it out. See a working demo that does this rather nicely.


[#88995] Friday, November 18, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ashelye

Total Points: 479
Total Questions: 97
Total Answers: 85

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
;