I try to use the onbeforeunload javascript event to ask the user if they want to leave the page, but I do not want the event to fire (EDIT: βeventβ is the dialog box that appears the user clicks βOKβ to leave the site, or click "Cancel" to stay on the current page) if the user clicks the "Back" button, as they are likely to remain on my site.
So, is there a way to find out if the user clicked the button back using javascript or PHP?
I have a solution using a hidden iframe that only works in IE, but I need something that can be used for Firefox, Chrome and Safari, if possible.
EDIT: my IE solution works because when the user accesses the back button, the iframe is sent back, but the parent page remains in the same place. From this, I can say that the user really clicked the back button, so I use history.back (). This little hack doesn't work in any other browser (as far as I know), so I'm looking for a cross-browser solution.
tl; dr I use window.onbeforeunload to open a dialog box asking users if they want to leave my site or not. I do not want this to pop up when the user clicks the back button. How can I say that the user clicked the back button in his browser?
Thanks Rick
source share