在iOS系统中每次提示信息上面都会被添加一行URL地址

最近移动端项目用alert和confirm进行信息提示,但发现在iOS系统中,
每次提示信息上面都会被添加一行URL地址 ;解决的方法是重写它们


重写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;
 };

猜你喜欢

转载自blog.csdn.net/qq_41046717/article/details/80777286