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; };
本文介绍了一种在网页中使用自定义方式实现alert和confirm弹窗的方法,通过创建隐藏的iframe来绕过浏览器的安全限制,使得开发者可以在各种环境中实现统一的提示框样式。
3万+

被折叠的 条评论
为什么被折叠?



