I was thinking of doing something with the jQuery.browser but this only returns which browser you're in and if its a webkit etc etc.
So i basically want to turn off certain js files from even loading if you're on a mobile device?
I assume you can do it but how?
To detect if the user is using a mobile device in JavaScript, we can use the userAgent property. This property is part of the navigator object and sent by the browser in HTTP headers. It contains information about the name, version, and platform of the browser.
matchMedia() The Window. matchMedia() is one of the best properties for detecting mobile users with JavaScript.
Go to the Settings or Options menu, scroll to the bottom of the list, and check 'About phone', 'About device' or similar. The device name and model number should be listed.
I think this answer is better because it doesn't depends on screen width:
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
// some code..
}
I know that now you've got a brand browser dependency, but this is a bit more maintainable that checking for the screen size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With