标签:move create html attribute cti nbsp result 查找 return
前几天写移动端项目用alert和confirm进行信息提示,但发现在iOS系统中,每次提示信息上面都会被添加一行URL地址,安卓却没有,经过查找之后,果然不出所料,兼容!!兼容!!!兼容!!!
需要重新alert和confirm,不废话,,看代码!
alert重写
<script type="text/javascript"> var wAlert = window.alert; window.alert = function (message) { try { 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 iwindow = alertFrame.window; if (iwindow == undefined) { iwindow = alertFrame.contentWindow; } iwindow.alert(message); iframe.parentNode.removeChild(iframe); } catch (exc) { return wAlert(message); } } </script>
confirm重写
<script> var wConfirm = window.confirm; window.confirm = function (message) { try { 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 iwindow = alertFrame.window; if (iwindow == undefined) { iwindow = alertFrame.contentWindow; } var result=iwindow.confirm(message); iframe.parentNode.removeChild(iframe); return result; } catch (exc) { return wConfirm(message); } } var r=confirm("Press a button"); if (r==true) { document.write("You pressed OK!"); } else { document.write("You pressed Cancel!"); } </script>
然后了解到html中data类型的url如下:
data:,<文本数据>
data:text/plain,<文本数据>
data:text/html,<HTML代码>
data:text/html;base64,<base64编码的HTML代码>
data:text/css,<CSS代码>
data:text/css;base64,<base64编码的CSS代码>
data:text/javascript,<Javascript代码>
data:text/javascript;base64,<base64编码的Javascript代码>
data:image/gif;base64,base64编码的gif图片数据
data:image/png;base64,base64编码的png图片数据
data:image/jpeg;base64,base64编码的jpeg图片数据
data:image/x-icon;base64,base64编码的icon图片数据
IOS移动端(H5)alert/confirm提示信息去除url
标签:move create html attribute cti nbsp result 查找 return
原文地址:https://www.cnblogs.com/smallclown/p/9334102.html