Skip to content

Instantly share code, notes, and snippets.

@cloudxero
Created March 5, 2012 22:36
Show Gist options
  • Save cloudxero/1981650 to your computer and use it in GitHub Desktop.
Save cloudxero/1981650 to your computer and use it in GitHub Desktop.
Dynamic loading of JS with mobile API.
(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