ITPub博客

首页 > 应用开发 > > 关于onbeforeunload在手机默认浏览器上不起作用

关于onbeforeunload在手机默认浏览器上不起作用

作者:xiaojun63 时间:2019-08-19 09:29:14 0 删除 编辑

各位大神好,请帮帮忙,非常谢谢!

以下几种方法,我都用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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-12

  • 博文量
    243
  • 访问量
    3053