隐藏alert弹框中的localhost:8080(ip地址跟端口号)

您所在的位置:网站首页 怎样更改微信ip地址信息 隐藏alert弹框中的localhost:8080(ip地址跟端口号)

隐藏alert弹框中的localhost:8080(ip地址跟端口号)

2024-07-08 22:13| 来源: 网络整理| 查看: 265

在前端页面中加入下面js代码即可(作用 重写alert方法)

//重写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 不显示ip地址 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); }

重写alert方法后的样子如下图所示 在这里插入图片描述 当然啦,也可使用下面的js代码来自定义我们的alert弹框

window.alert = function(str) { var shield = document.createElement("DIV"); shield.id = "shield"; shield.style.position = "absolute"; shield.style.left = "0px"; shield.style.top = "0px"; shield.style.width = "100%"; shield.style.height = document.body.scrollHeight+"px"; //弹出对话框时的背景颜色 shield.style.background = "#fff"; shield.style.textAlign = "center"; shield.style.zIndex = "25"; //背景透明 IE有效 //shield.style.filter = "alpha(opacity=0)"; var alertFram = document.createElement("DIV"); alertFram.id="alertFram"; alertFram.style.position = "absolute"; alertFram.style.left = "50%"; alertFram.style.top = "50%"; alertFram.style.marginLeft = "-225px"; alertFram.style.marginTop = "-75px"; alertFram.style.width = "450px"; alertFram.style.height = "150px"; alertFram.style.background = "#ff0000"; alertFram.style.textAlign = "center"; alertFram.style.lineHeight = "150px"; alertFram.style.zIndex = "300"; strHtml = "\n"; strHtml += " [自定义提示]\n"; strHtml += " "+str+"\n"; strHtml += " \n"; strHtml += "\n"; alertFram.innerHTML = strHtml; document.body.appendChild(alertFram); document.body.appendChild(shield); var ad = setInterval("doAlpha()",5); this.doOk = function(){ alertFram.style.display = "none"; shield.style.display = "none"; } alertFram.focus(); document.body.onselectstart = function(){return false;}; }

效果图如下图所示 在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3