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
- <span style="font-size:10px;" > <script>
- 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);
- }
- Alert (' xxx ');
- </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
- var result = window.frames[0].window.confirm (name);
- Iframe.parentNode.removeChild (IFRAME);
- return result;
Address: http://blog.csdn.net/hx_lei/article/details/51212336
Remove the URL (URL) of iOS mobile alert/confirm