Last active
December 20, 2015 03:29
-
-
Save jacquarg/6064167 to your computer and use it in GitHub Desktop.
Device-aware javascript redirection.
http://www.hoodbrains.com/2012/12/un-lien-unique-pour-telecharger-une-application-sur-lapp-store-ou-le-play-store/
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
| <SCRIPT language=javascript> | |
| function redirectOnUserAgent() { | |
| var mapping = { | |
| // default : | |
| "_default" : "http://www.appsfit.com", | |
| // scheme : market://details?id=<package_name> | |
| "android": "market://details?id=com.appsfit.android", | |
| //scheme : itms-apps://itunes.apple.com/app/id<numeric_app_id> | |
| "iphone": "itms-apps://itunes.apple.com/app/id574406974", | |
| // if availables : | |
| "ipad": "itms-apps://itunes.apple.com/app/id574406974", | |
| "ipod":"itms-apps://itunes.apple.com/app/id574406974", | |
| // BlackBerry | |
| //scheme : http://appworld.blackberry.com/webstore/content/app_content_id | |
| // User Agent BlackBerry 10 | |
| "bb10": "http://appworld.blackberry.com/webstore/content/12345", | |
| // User Agent BlackBerry 6 et 7 | |
| "blackberry": "http://appworld.blackberry.com/webstore/content/12345", | |
| // User Agent PlayBook | |
| "playbook": "http://appworld.blackberry.com/webstore/content/12345", | |
| // Windows Phone | |
| //scheme : http://www.windowsphone.com/s?appid=YOURAPPID | |
| "windows phone": "http://www.windowsphone.com/s?appid=12345", | |
| // Amazon | |
| // scheme : amzn://apps/android?p=[package_name] | |
| "kindle" : "amzn://apps/android?p=com.angrybirds" | |
| } | |
| var userAgent = navigator.userAgent.toLowerCase(); | |
| for (var dev in mapping) { | |
| if (userAgent.search(dev) != -1) { | |
| window.location = mapping[dev]; | |
| return; | |
| } | |
| } | |
| // else redirect to another page, or comment-it to stay on this one. | |
| window.location = mapping["_default"]; | |
| } | |
| </SCRIPT> | |
| <BODY onload="redirectOnUserAgent();"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment