Load JQuery Mobile script only for mobile devices

前端 未结 2 1225
闹比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条回答
  • 2020-12-15 09:55

    How about determining whether to use a mobile layout based on device width, like CSS frameworks such as Twitter Bootstrap do? This way, you can design for small devices using jQuery mobile and for others with vanilla jQuery? Testing with yepNope or similar still applies, I think.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题