Created
January 25, 2013 05:28
-
-
Save drawcode/4632001 to your computer and use it in GitHub Desktop.
....
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <meta name="viewport" content="width=device-width" /> | |
| </head> | |
| <body> | |
| <h2><a id="applink1" href="fb://profile/116201417">open facebook with fallback to appstore</a></h2> | |
| <h2><a id="applink2" href="unknown://nowhere">open unknown with fallback to appstore</a></h2> | |
| <p><i>Only works on iPhone!</i></p> | |
| <script type="text/javascript"> | |
| // To avoid the "protocol not supported" alert, fail must open another app. | |
| var appstore = "itms://itunes.apple.com/us/app/facebook/id284882215?mt=8&uo=6"; | |
| function applink(fail){ | |
| return function(){ | |
| var clickedAt = +new Date; | |
| // During tests on 3g/3gs this timeout fires immediately if less than 500ms. | |
| setTimeout(function(){ | |
| // To avoid failing on return to MobileSafari, ensure freshness! | |
| if (+new Date - clickedAt < 2000){ | |
| window.location = fail; | |
| } | |
| }, 500); | |
| }; | |
| } | |
| document.getElementById("applink1").onclick = applink(appstore); | |
| document.getElementById("applink2").onclick = applink(appstore); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment