在H5网站开发中经常会出现alert提示,IOS手机会显示出网址,以下的js代码可以解决这个问题
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);
}
}
专注于网站开发、H5网站开发。美观、快速、稳定、安全是我们不懈的追求。
版权所有 2018 顺道电子商务有限公司