Skip to content

Instantly share code, notes, and snippets.

@psalter27
Created September 21, 2011 09:44
Show Gist options
  • Save psalter27/1231681 to your computer and use it in GitHub Desktop.
Save psalter27/1231681 to your computer and use it in GitHub Desktop.
detectDevice function that is bound to a click action
$(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