iOS Mobile of H5 alert and confirm Prompt Removal URL of URL

  • 2021-06-29 12:11:17
  • OfStack

Recent mobile projects have used alert and confirm for informational prompts, but found that in the iOS system, a line of URL address is added to each prompt.

So how to remove the address hint? Find and implement the methods to override alert and confirm to solve this problem.
The code is as follows:

Override the alert method:


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);
 };

Override the confirm method:


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;
 };

The confirm method is the result of the return subframework.Otherwise, the default is to cancel the effect.

Derived Points of Knowledge:

url of data type in html

For small data, you can embed it directly in a web page instead of loading it from an external file, such as a picture.This has the advantage of reducing one http request, but it has the disadvantage of making the page content larger.url format of data type was introduced in 1998. Most browsers now support it, such as domestic browsers using IE6 kernel, chrome and firefox, but there are problems with IE8 and the picture display is incomplete.

url of type data has the following forms:


 data:,< Text Data > 
 data:text/plain,< Text Data > 
 data:text/html,<HTML Code > 
 data:text/html;base64,<base64 Coded HTML Code > 
 data:text/css,<CSS Code > 
 data:text/css;base64,<base64 Coded CSS Code > 
 data:text/javascript,<Javascript Code > 
 data:text/javascript;base64,<base64 Coded Javascript Code > 
 data:image/gif;base64,base64 Coded gif Picture data  
 data:image/png;base64,base64 Coded png Picture data  
 data:image/jpeg;base64,base64 Coded jpeg Picture data  
 data:image/x-icon;base64,base64 Coded icon Picture data  

Related articles: