disabling a javascript script when loaded on a smart phone

那年仲夏 提交于 2020-01-24 00:25:41

问题


I am using the following HTML fragment to load a different stylesheet for smartphones:

media="only screen and (min-device-width: 4801x)"
media="only screen and (max-device-width: 480px)"

I would like to disable a certain javascript script for smartphone users as well. Is that possible? I don't think i can do:

<script media="only screen and (max-device-width: 480px)" t ype="text/javascript" src=""/>

Thanks


回答1:


You can detect the screen resolution in javascript and then change script execution based on the resolution. But the javascript file will still be loaded. To detect the screen size:

http://www.pageresource.com/jscript/jscreen.htm




回答2:


No, it's not possible.

If the phone's browser does not support javascript then it won't matter. If it does, you can use javascript to determine whether it supports what you are looking for and, if not, divert the execution to either a simpler path or to exit altogether.



来源:https://stackoverflow.com/questions/2053695/disabling-a-javascript-script-when-loaded-on-a-smart-phone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!