-
-
Save shuiRong/01809aaaa2dad6873a23831b7de45e77 to your computer and use it in GitHub Desktop.
重写alert,confirm 去除标题中URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var wAlert = window.alert; | |
window.alert = 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; | |
} | |
iwindow.alert(message); | |
iframe.parentNode.removeChild(iframe); | |
} | |
catch (exc) { | |
return wAlert(message); | |
} | |
} | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment