How to detect if the user clicked the "back" button
back-button, javascript, jquery, jquery-events
Solution
You generally can't (browser security restriction). You can tell if the user navigates away from the page (onbeforeunload, onunload fire) but you can't tell where they went unless you've set up your page to allow it.
HTML5 introduces the HTML5 History API; in conforming browsers, the onpopstate event will fire if the user navigates back to an earlier "page" on your site.
Problem
When the user goes history-back-1...how do I detect that? And then, alert "the user clicked back!" Using binds (and jQuery preferably)
Related problems
- Using Javascript: How to create a 'Go Back' link that takes the user to a link if there's no history for the tab or window?
- Is there a way using Jquery to detect the back button being pressed cross browsers
- In Javascript, preferably JQuery, how do I add something to the URL when the user clicks "back" button in the browser?