如何去掉JS函数alert显示的域名

    选择打赏方式

日常开发经常会使用到Javascript自带的alert函数来弹窗提示访客,但它是会显示本站域名的,如果想隐藏掉域名呢?要怎么做?

alert隐藏域名.png

简单几行代码解决:

(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);
    }
})();

版权声明:若无特殊注明,本文为《傲世》原创,转载请保留文章出处。
本文链接:https://www.recho.cn/206.html
如您对本文章内容有所疑问、反馈或补充,欢迎通过邮箱:[email protected] 联系我们!
正文到此结束

热门推荐