js 监听返回键
js
window.onload = function(){
window.addEventListener('popstate', function (e) {
alert('监听到了返回');
});
window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
window.history.forward(1);
}
jq
$(document).ready(function(e) {
var counter = 0;
if (window.history && window.history.pushState) {
$(window).on('popstate', function () {
alert('监听到了返回');
});
}
window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
window.history.forward(1);
});