提示框.png
在微信公衆號開發的時候在使用【alert/confirm】彈出提示或者警告信息的時候會出現如上圖中紅色方框中的問題,【alert/confirm】會將該公衆號的網址顯示出來,這樣很不美觀。所以很多時候我們會選擇去除那個網址提示內容。解決方法如下:
重寫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方法:
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;
};