I tried the following code:
window.onbeforeunload = function() { return "Your work will be lost."; };
But even I click on a button of my page, I get an alert message. I want to detect just the back button event. How can I do that?
I tried the following code:
window.onbeforeunload = function() { return "Your work will be lost."; };
But even I click on a button of my page, I get an alert message. I want to detect just the back button event. How can I do that?
window.onbeforunload = ... will run the function when ever the page is left. since the back button is liked to the browser and not the site, its hard to edit its function, but this link helps a lot when trying to get around this http://www.irt.org/script/311.htm. hope this helps :)
The best solution I found is to add the following code in the script block:
<script type="text/javascript">
window.location.hash="no-back-button";
window.onhashchange=function(){
window.location.hash="no-back-button";
}
// your code
</script>