在做微信公众号开发时IOS端的微信浏览器打开,触发confirm以及alert时弹出框会有附带当前网址信息,Android端的没有测试,不知道是否有同样的情况。
解决办法如下:
“`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);
}
;
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;
}
;
alert('abc');
confirm('are you sure?');
“`
以上这篇IOS微信端confirm以及alert去掉网址的实例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- iOS移动端(H5)alert/confirm提示信息去除网址(URL)