zl程序教程

您现在的位置是:首页 >  前端

当前栏目

jquery判断浏览器后退时候弹出消息的方法

jQuery方法消息浏览器 判断 时候 后退
2023-06-13 09:15:41 时间

浏览器后退时必定会有一些消息,这里使用jquery判断浏览器后退并弹出消息

jQuery(document).ready(function($){
if(window.history&&window.history.pushState){
$(window).on("popstate",function(){
varhashLocation=location.hash;
varhashSplit=hashLocation.split("#!/");
varhashName=hashSplit[1];
if(hashName!==""){
varhash=window.location.hash;
if(hash===""){
alert("Backbuttonisn"tsupported.Youareleavingthisapplicationonnextclickingthebackbutton");
}
}
});
window.history.pushState("forward",null,"./#forward");
}
});