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.
            Asked
            
        
        
            Active
            
        
            Viewed 364 times
        
    1
            
            
        - 
                    You could detect the OS based on user agaent and call different functions or even load different js dynamically. – VJS Dec 06 '13 at 11:04
- 
                    I think http://davidwalsh.name/device-state-detection-css-media-queries-javascript might help – Andrew Dec 06 '13 at 11:07
2 Answers
3
            
            
        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
 
    
    
        Community
        
- 1
- 1
 
    
    
        actual_kangaroo
        
- 5,971
- 2
- 31
- 45
- 
                    I want to make a distinction between touch and non-touch devices, is that possible with Modernizr? – Luc Dec 06 '13 at 11:07
- 
                    absolutely http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript – actual_kangaroo Dec 06 '13 at 11:08
0
            
            
        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....
 
    
    
        NavaStha
        
- 96
- 6
