tell html doc not to load js if mobile device

后端 未结 5 1097
悲&欢浪女
悲&欢浪女 2020-12-09 05:13

I\'m cheekily seeking a line or two of code on the fly here:

Could someone be kind enough to provide code to place in the head section of html doc that says if mobil

5条回答
  •  Happy的楠姐
    2020-12-09 05:44

    Given: "if mobile then do not load JS", and presuming "mobile" is defined by screens with a width of 480 pixels or less, then something like the following should work:

    
    

    That will add the script element only if the screen is greater than 480 pixels wide.

    The CSS rule in the OP is:

    <... media="only screen and (max-device-width: 480px)" ...>
    

    which will target screens of 480 pixels or less, which is contrary to to the first statement. Therefore change > to <= if the script should run on small screens and not run on larger ones.

提交回复
热议问题