系统默认的alert弹出框总会带有域名

最近在开发Hybrid APP时发现用系统默认的alert弹出框总会带有域名,用户体验就比较不好了。想了一种办法来解决就是覆盖alert的方法。

(function(){
       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('试一试');

完美解决!

原文地址:https://www.cnblogs.com/longling2344/p/8267264.html