Reputation: 1825
Is there a way I can call on different javascript files or lines depending on which device you view the site on? Like media queries for css.
Upvotes: 1
Views: 407
Reputation: 6071
there are a few general approaches to this:
check the user agent string on the server and return different scripts
I recommend the first approach using modernizr http://modernizr.com/
EDIT:
detecting a touch aware browser with modernizr:
modernizr will add class="touch'
to the body
$('.touch #popup).hide() // hide "popup" only on touch devices
Upvotes: 3
Reputation: 96
Devices in context of platforms such as android, iphone, ipad, ie mobile etc, we can simply check as:
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
// here is your javascript code....
}
Hope, devices means to be worked as above....
Upvotes: 0