i want to access browser previous or next button using jQuery.When i click browser previous button i want to see alert("yes"); or any response.is it possible?
问问题
1299 次
1 回答
5
Yes. It is (somehow) possible in HTML5. It does not require jQuery. Use onpopstate
for that.
MDN: https://developer.mozilla.org/en/DOM/window.onpopstate
window.onpopstate = function(event) {
alert("location: " + document.location);
};
But in order to use onpopstate
, you will have to use pushState
first.
DEMO: http://jsfiddle.net/DerekL/LZCj7/show
PS: it is originally made for AJAX applications.
Alternative method:
<body onbeforeunload="return 'This is an alert.'">
于 2012-05-28T21:02:42.513 回答