iOS移動端(H5)alert/confirm提示資訊去除網址(URL)_IOS

來源:互聯網
上載者:User

最近移動端項目用alert和confirm進行資訊提示,但發現在iOS系統中,每次提示資訊上面都會被添加一行URL地址。

那麼如何去掉地址提示呢,經尋找和實現發現進行重寫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; };

其中confirm方法要return子架構的結果。否則預設都是“取消”的效果。

衍生知識點:

html中data類型的url

針對於一些小的資料,可以在網頁中直接嵌入,而不是從外部檔案載入,比如圖片。這樣的好處是可以減少一次http的請求,缺點是使得頁面內容變大。data類型的url格式在98年就已經提出了,現在絕大部分的瀏覽器都能支援,比如使用IE6核心的國內瀏覽器,chrome和firefox等,但IE8上使用有問題,圖片顯示不完整。

data類型的url有以下幾種形式:

 data:,<文本資料>  data:text/plain,<文本資料>  data:text/html,<HTML代碼>  data:text/html;base64,<base64編碼的HTML代碼>  data:text/css,<CSS代碼>  data:text/css;base64,<base64編碼的CSS代碼>  data:text/javascript,<Javascript代碼>  data:text/javascript;base64,<base64編碼的Javascript代碼>  data:image/gif;base64,base64編碼的gif圖片資料  data:image/png;base64,base64編碼的png圖片資料  data:image/jpeg;base64,base64編碼的jpeg圖片資料  data:image/x-icon;base64,base64編碼的icon圖片資料 

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.