移动端ios去除alert和confirm弹框链接

     近期在做一个移动项目的时候,在测试中发现 alert 和 confirm 在ios 端的弹框会附带网页链接,很烦人,经过仔细研究发现进行重写alert和confirm方法可解决此问题。 

    

  关于alert 去除链接,代码如下:

         window.alert = function(name){  
                     var iframe = document.createElement("IFRAME");  
                    iframe.style.display="none";  
                    iframe.setAttribute("src", 'data:text/plain,');  
                    document.documentElement.appendChild(iframe);  
                    window.frames[0].window.alert(name);  
                    iframe.parentNode.removeChild(iframe);  
        }  
        alert('Hello world!'); 

   关于confirm去除链接,代码如下:

        window.confirm = function (message) {
           var iframe = document.createElement("IFRAME");
           iframe.style.display = "none";
           iframe.setAttribute("src", 'data:text/plain,');
           document.documentElement.appendChild(iframe);
           var alertFrame = window.frames[0];
           var result = alertFrame.window.confirm(message);
           iframe.parentNode.removeChild(iframe);
           return result;
         };
         confirm("是否有链接?")

其中confirm方法要return子框架的结果。否则默认都是“取消”的效果。

 

在ios 端还有一个问题,就是alert和confirm 用ios端微信内置浏览器打开的时候,都是英文显示,这个问题暂时没有很好的解决,只能重新模一个alert 和 confirm出来。之后会继续研究,如有更好的方法会继续更新,多谢关注。

转载于:https://www.cnblogs.com/leeyen/p/js.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值