js中的alert提示框去掉ip地址或域名
阿新 • • 發佈:2019-01-24
在js程式碼塊中新增以下程式碼,可以去掉瀏覽器預設alert標題為ip地址或者域名
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);
};
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;
};