微信开发IOS端alert/confirm提示信息去除网址(URL)的方法

参考链接:http://www.xuetn.com/share/201704/588611.html

提示框.png

    在微信公众号开发的时候在使用【alert/confirm】弹出提示或者警告信息的时候会出现如上图中红色方框中的问题,【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);
 };

重写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;
 };
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容