public
Created

Dynamic loading of JS with mobile API.

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
(function () {
'use strict';
 
var head, script, siteid, domain, internal, mobilesite;
 
head = document.getElementsByTagName('head')[0];
script = document.createElement('script');
siteid = 20755;
domain = new RegExp('jimmcnatttoyota.com', 'i');
mobilesite = 'http://m.jimmcnatttoyota.com';
internal = document.referrer.search(domain);
 
script.type = 'text/javascript';
script.src = 'http://api.handsetdetection.com/sites/js/' + siteid + '.js';
script.onload = function () {
jQuery(document).ready(function () {
if (HandsetDetection.ismobile === true) {
document.location = mobilesite;
}
});
};
if (internal === -1) {
head.appendChild(script);
}
}());

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.