I would like to load different scripts if the user is on a smartphones/tablets or on a laptop.
Here is the result that I want :
Laptop:
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
smartphones and tablets
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
How can I do it?
You’re looking at either sniffing the User-Agent to detect for specific devices or you can use the browser/screen width to determine which category your user falls under.
To add scripts based on browser width you can do something like this:
This has a few caveats though.
<=1024pxwide so you’ll have some overlap between tablet and desktop users.The CSS/JS inclusion will most likely work for you no matter how you detect mobile/tablet devices. There are scripts out there to detect devices that run server-side as well as client-side, a quick Google search will bring up many of these scripts. I have not used these scripts however so I can’t offer much guidance on their usage.