Luc
Luc

Reputation: 1825

Separate javascript for different devices

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

Answers (2)

roo2
roo2

Reputation: 6071

there are a few general approaches to this:

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

NavaStha
NavaStha

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

Related Questions