Created
March 5, 2012 22:36
-
-
Save cloudxero/1981650 to your computer and use it in GitHub Desktop.
Dynamic loading of JS with mobile API.
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
(function () { | |
'use strict'; | |
var head, script, siteid, domain, internal, mobilesite; | |
siteid = 20755; | |
domain = new RegExp('jimmcnatttoyota.com', 'i'); | |
mobilesite = 'http://m.jimmcnatttoyota.com'; | |
head = document.getElementsByTagName('head')[0]; | |
script = document.createElement('script'); | |
internal = document.referrer.search(domain); | |
script.type = 'text/javascript'; | |
script.src = 'http://api.handsetdetection.com/sites/js/' + siteid + '.js'; | |
if (internal === -1) { | |
head.appendChild(script); | |
} | |
script.onload = function () { | |
if (HandsetDetection.ismobile === true) { | |
document.location = mobilesite; | |
} | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment