Last time I made a Web APP for my website based on online tutorials, but it gave users a very bad feeling.
Question description:
What's wrong? It turns out that after opening the WEB APP, you will open the connection at will on the homepage, and you will open the Safari browser on your own initiative. It turns out that the good disguise and mood were completely destroyed. What should I do? It turns out that the solution is very simple. Just add these codes. The experimental test was passed on my iPhone (iOS 7.1) and iPod (iOS 6.1.4). According to the original author's statement, the latest iOS 7.0.4 (iPhone and iPad) test passed, and the code should have good compatibility. Share it here:
Problem Solving:
The code copy is as follows:
<script type="text/javascript">
//The problem of clicking the link in iOS Web APP to jump to the new tab page of Safari browser
if (("standalone" in window.navigator) && window.navigator.standalone) {
var noddy, remotes = false;
document.addEventListener('click',
function(event) {
noddy = event.target;
while (noddy.nodeName !== “A” && noddy.nodeName !== “HTML”) {
noddy = noddy.parentNode;
}
if ('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) {
event.preventDefault();
document.location.href = noddy.href;
}
},
false);
}
</script>
It is recommended to put the code in front of the /head tag. Of course, it is also OK to save it as a js file reference.