微信開發IOS端alert/confirm提示信息去除網址(URL)的方法

 

參考鏈接:http://www.xuetn.com/share/201704/588611.html

提示框.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;
 };

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章