浏览器的上一个或下一个按钮控件

alt*_*gan 1 javascript jquery

我想使用jQuery访问浏览器上一个或下一个按钮.当我点击浏览器上一个按钮我想看到警报("是"); 或任何回应.这可能吗?

Der*_*會功夫 5

是.它(以某种方式)在HTML5中是可能的.它不需要jQuery.使用onpopstate了点.

MDN:https://developer.mozilla.org/en/DOM/window.onpopstate

window.onpopstate = function(event) {  
    alert("location: " + document.location);  
};
Run Code Online (Sandbox Code Playgroud)

但是为了使用onpopstate,你必须先使用pushState.

演示: http ://jsfiddle.net/DerekL/LZCj7/show

PS:它最初是为AJAX应用程序而制作的.

替代方法:

<body onbeforeunload="return 'This is an alert.'">
Run Code Online (Sandbox Code Playgroud)