Created
September 21, 2011 09:44
-
-
Save psalter27/1231681 to your computer and use it in GitHub Desktop.
detectDevice function that is bound to a click action
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
$(document).ready(function() { | |
//Global function that will detect what device the page is being viewed on | |
function globalDetectDevice() { | |
var deviceIphone = "iphone" ; | |
var deviceIpod = "ipod" ; | |
var deviceAndroid = "android" ; | |
//Initialize our user agent string to lower case. | |
var uagent = navigator.userAgent.toLowerCase() ; | |
function DetectDevice() { | |
if ((uagent.search(deviceIphone) > -1) || (uagent.search(deviceIpod) > -1) || (uagent.search(deviceAndroid) > -1)) { | |
window.location = "/landing/register/mobile" ; | |
} | |
else { | |
//do nothing | |
} | |
} | |
} | |
//Binding the above function to a class, that we can then attach to any clickable element | |
//As jQuery is at the bottom of page, we poll the function until jQuery has loaded, once loaded, we clear the polling using clearTimout | |
var bindTimer = setInterval(function() { | |
if ("undefined" != typeof jQuery && globalDetectDevice) { | |
$('.detectDevice').bind('click', DetectDevice();); | |
clearTimeout(bindTimer); | |
} | |
}, 50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment