Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5585 | obado | 1 | (function(document,navigator,standalone) { |
2 | // Script found at https://gist.github.com/1042167 |
||
3 | // prevents links from apps from oppening in mobile safari |
||
4 | // this javascript must be the first script in your <head> |
||
5 | if ((standalone in navigator) && navigator[standalone]) { |
||
6 | var curnode, location=document.location, stop=/^(a|html)$/i; |
||
7 | document.addEventListener('click', function(e) { |
||
8 | curnode=e.target; |
||
9 | while (!(stop).test(curnode.nodeName)) { |
||
10 | curnode=curnode.parentNode; |
||
11 | } |
||
12 | // Condidions to do this only on links to your own app |
||
13 | // if you want all links, use if('href' in curnode) instead. |
||
14 | if('href' in curnode && ( curnode.href.indexOf('http') || ~curnode.href.indexOf(location.host) ) ) { |
||
15 | e.preventDefault(); |
||
16 | location.href = curnode.href; |
||
17 | } |
||
18 | },false); |
||
19 | } |
||
20 | })(document,window.navigator,'standalone'); |