各位大神好,请帮帮忙,非常谢谢!
以下几种方法,我都用Android和iPhone 手机的自带浏览器,试过了,没效果。
Android手机上chrome和Firefox浏览器 onbeforeunload 是有效果的。
请问怎样才能在手机的自带浏览器上实现:在离开当前页面时,弹窗提示,是否离开当前页面,否的话就留在当前页面?
1.window.onbeforeunload = function(e) {
e = window.event || e;
if(e) { e.returnValue = "你确定离开吗?"; }
return “你确定离开吗?”
};
2.window.addEventListener("beforeunload",function(){ return “你确定离开吗?”},false);
3.window.onunload = function(e) {
e = window.event || e;
if(e) { e.returnValue = "你确定离开吗?"; }
return “你确定离开吗?”
};
4.window.onpagehide = function(e) {
e = window.event || e;
if(e) { e.returnValue = "你确定离开吗?"; }
return “你确定离开吗?”
};
5.document.onvisibilitychange = function(){
if(document.visibilityState == "hidden"){
//......
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/658/viewspace-3130799/ ,如需转载,请注明出处,否则将追究法律责任。