Remove the URL (URL) of iOS mobile alert/confirm

Source: Internet
Author: User

On the mobile side using the native alert/confirm will always show the URL (URL), the interface looks ugly, search for half a day can not find a solution, in despair when you see an article written very well, in this thank http://ifindever.com/archives/ 260.html, but also hope to help everyone.

Recently in a small creator WebApp, encountered a problem, the previous version, iOS and Android can be overridden by the WebView alert and other pop-up window events to hide the title of the pop-up window, but after the iOS7, the API is disabled, so that iOS cannot rewrite the hidden title:

1. The iOS native code is invoked via JS, i.e.: Window.alert = function (str) {window.local.href = "xx://str/" +str}

2.JS+HTML+CSS simulation, but in order to implement blocking execution such as alert, it is necessary to put the following code into the callback function to execute

But still feel that these two ways to achieve is not too elegant, all need to make a big change to the existing code, do not forget, so continue Google, finally found a good way:

[JavaScript]View PlainCopy
  1. <span style="font-size:10px;" > <script>
  2. Window.alert = function (name) {
  3. var iframe = document.createelement ("iframe");
  4. iframe.style.display="None";
  5. Iframe.setattribute ("src", ' Data:text/plain, ');
  6. Document.documentElement.appendChild (IFRAME);
  7. Window.frames[0].window.alert (name);
  8. Iframe.parentNode.removeChild (IFRAME);
  9. }
  10. Alert (' xxx ');
  11. </script></span>


This method is to rewrite the alert method (Confirm method), do not need to change the existing code, and solve the pop-up title of the URL problem. However, it is important to note that each time you execute a alert/confirm in the framework, you need to remove the framework and reload it next time, otherwise it will cause cross-domain execution in chrome, which is blocked by Chrome.

There are also confirm, after rewriting the window.confirm, the confirmation and cancellation of the clicked event is the execution of the cancellation, it is necessary to write:

Confirm needs the result of the return sub-frame:

[JavaScript]View PlainCopy
      1. var result = window.frames[0].window.confirm (name);
      2. Iframe.parentNode.removeChild (IFRAME);
      3. return result;

Address: http://blog.csdn.net/hx_lei/article/details/51212336

Remove the URL (URL) of iOS mobile alert/confirm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.