Skip to content

Instantly share code, notes, and snippets.

@adeolaawoyemi
Created September 21, 2011 09:14
Show Gist options
  • Save adeolaawoyemi/1231640 to your computer and use it in GitHub Desktop.
Save adeolaawoyemi/1231640 to your computer and use it in GitHub Desktop.
wait for jQuery before using it to bind
var bindTimer = setInterval(function() {
if ("undefined" != typeof jQuery && isMobileDevice) {
$('.myclass').bind('click', clickHandlerToMobilePage);
clearTimeout(bindTimer);
}
}, 50);
@psalter27
Copy link

$(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);

}

@psalter27
Copy link

damn, obviously can't do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment