I have to capture if user clicks on back button of browser(IE, Chrome and Firefox)
I don't want onbeforeunload event to be called when user presses the back button of browser
I have to capture if user clicks on back button of browser(IE, Chrome and Firefox)
I don't want onbeforeunload event to be called when user presses the back button of browser
Update In the following function when u click on links you will see the event being fired....now after clicking on any link click back button youll agin c the event being fired.
$(window).bind( "hashchange", function(e) {
alert()
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://github.com/cowboy/jquery-bbq/raw/v1.2.1/jquery.ba-bbq.min.js"></script>
<nav id="siteNav">
<ul>
<li class="nav1"><a href="#landing" title="Home">Home</a>
<li class="nav2"><a href="#products" title="Products">Products</a>
<li class="nav3"><a href="#about-us" title="About Us">About Us</a>
<li class="nav4"><a href="#sign-up" title="Sign Up">Sign Up</a>
<li class="nav5"><a href="" title="Videos">Videos</a>
</ul>
</nav>
Use the hashchange
event:
window.addEventListener("hashchange", function(e) {
// ...
})
I was looking for the same thing a while ago, but the Back button event of the browsers cannot be listened to. But, if it could be handy, you can use jQuery (or Javascript) and use the .unload() method