Created
August 16, 2013 14:52
-
-
Save SoftCreatR/6250593 to your computer and use it in GitHub Desktop.
JS based mobile device detection for Tapatalk
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
/** | |
* Tapatalk mobile detection | |
* | |
* @author Sascha Greuel <[email protected]> | |
* @copyright 2013 Sascha Greuel | |
* @license Creative Commons BY-SA <http://creativecommons.org/licenses/by-sa/3.0/> | |
*/ | |
function detectTapatalk() { | |
var tapatalk_msg = 'This forum has an app for [platform]! Click OK to learn more about Tapatalk.', | |
tapatalk_ios_url = 'https://itunes.apple.com/us/app/id585178888', | |
tapatalk_ios_hd_url = 'https://itunes.apple.com/us/app/id481579541', | |
tapatalk_kindle_url = 'http://www.amazon.com/gp/mas/dl/android?p=com.quoord.tapatalkpro.activity', | |
tapatalk_kindle_hd_url = 'http://www.amazon.com/gp/mas/dl/android?p=com.quoord.tapatalkHD', | |
tapatalk_android_url = 'https://play.google.com/store/apps/details?id=com.quoord.tapatalkpro.activity', | |
tapatalk_android_hd_url = 'https://play.google.com/store/apps/details?id=com.quoord.tapatalkHD', | |
tapatalk_blackberry_url = 'https://appworld.blackberry.com/webstore/content/46654/', | |
tapatalk_windowsphone_url = 'https://www.windowsphone.com/s?appid=913ffd61-3ba0-435c-a894-9d3ec7e78d6e', | |
ua = navigator.userAgent.toLowerCase(); | |
if ((ua.match(/iphone|ipod/))) { | |
if (window.confirm(tapatalk_msg.replace(/\[platform\]/gi, 'iPhone'))) { | |
window.location = tapatalk_ios_url; | |
} | |
} else if (ua.match(/ipad/)) { | |
if (window.confirm(tapatalk_msg.replace(/\[platform\]/gi, 'iPad'))) { | |
window.location = tapatalk_ios_hd_url; | |
} | |
} else if (ua.match(/silk/i)) { | |
if (window.confirm(tapatalk_msg.replace(/\[platform\]/gi, 'Kindle'))) { | |
window.location = (ua.match(/android 2/) ? tapatalk_kindle_url : tapatalk_kindle_hd_url); | |
} | |
} else if (ua.match(/android/)) { | |
if (window.confirm(tapatalk_msg.replace(/\[platform\]/gi, 'Android'))) { | |
window.location = (ua.match(/mobile/) ? tapatalk_android_url : tapatalk_android_hd_url); | |
} | |
} else if (ua.match(/blackberry/)) { | |
if (window.confirm(tapatalk_msg.replace(/\[platform\]/gi, 'BlackBerry'))) { | |
window.location = tapatalk_blackberry_url; | |
} | |
} else if (ua.match(/iemobile|windows phone/)) { | |
if (window.confirm(tapatalk_msg.replace(/\[platform\]/gi, 'Windows Phone'))) { | |
window.location = tapatalk_windowsphone_url; | |
} | |
} | |
} | |
function setTapatalkCookies() { | |
var date = new Date(), | |
days = 90, | |
expires = '', | |
domain = ''; | |
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | |
expires = '; expires=' + date.toGMTString(); | |
domain = '; path=/'; | |
document.cookie = 'tapatalk=false' + expires + domain; | |
} | |
if (navigator.cookieEnabled && document.cookie.indexOf('tapatalk=false') < 0) { | |
setTapatalkCookies(); | |
detectTapatalk(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment