How do I detect the browsers back button is clicked in IE 11 browser. In IE <10 browsers we can achieve this functionality using the following:
(window.event.clientX < 40 && window.event.clientY < 0).
Please share your thoughts.
How do I detect the browsers back button is clicked in IE 11 browser. In IE <10 browsers we can achieve this functionality using the following:
(window.event.clientX < 40 && window.event.clientY < 0).
Please share your thoughts.
The code below will detect the back button's click. The /* Your code here! */ is whatever you want to do when the back button is clicked.
window.addEventListener("popstate", function (event) {
/* Your code here! */
}, false);
window.history.pushState({}, "", window.location.toString());
By default, clicking the back button will make it go back. To stop it, use event.preventDefault(). If you want to make it go back manually, just use window.history.back().
This will only work in IE11. IE10 or older doesn't support the history API.