Load JQuery Mobile script only for mobile devices

前端 未结 2 1228
闹比i
闹比i 2020-12-15 09:35

I have a web page that has to be correctly displayed on mobile devices. To do so, i loaded JQuery Mobile script in the page\'s head. The head tag looks like this:

         


        
2条回答
  •  Happy的楠姐
    2020-12-15 10:00

    Its hard to detect whether your device is mobile or tablet or huge screen with touch, but to start with

    1. Use script to detect from http://detectmobilebrowsers.com/
    2. Test using http://yepnopejs.com/

    Like this (should work for jQuery script from http://detectmobilebrowsers.com/) :

    yepnope({
      test : jQuery.browser.mobile,
      yep  : 'mobile_specific.js',
      nope : ['normal.js','blah.js']
    });
    

    EDIT:

    Also have a look at https://github.com/borismus/device.js, for loading content based on conditions. I am not sure whether it will allow you to load conditional JS files.

提交回复
热议问题