简体   繁体   English

如果(screen.availWidth>)禁用所有脚本?

[英]if ( screen.availWidth > ) disables all scripts?

I was looking for a way to disable prettyPhoto lightbox on small devices (since the popups were smaller than the displayed images in the gallery on the page, and the thing generally looked ugly that small), and I came across 我一直在寻找一种在小型设备上禁用prettyPhoto灯箱的方法(因为弹出窗口小于页面上画廊中显示的图像,而且看起来通常很小,所以看上去很丑),我遇到了

   if ( screen.availWidth > 500 ) { << jquery script code here >> };

This neatly fixed things and disabled the gallery script on devices smaller than 500px wide. 这样可以很好地解决问题,并禁用了宽度小于500像素的设备上的Gallery脚本。 But it also disabled all the other linked js files. 但它也禁用了所有其他链接的js文件。

How come adding the availWidth line to the top of 1 script influences everything else? 将availWidth行添加到1个脚本的顶部会如何影响其他所有内容? The order in which the scripts are called doesn't seme to matter (in <head> ): 调用脚本的顺序并不重要(在<head> ):

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="../scripts/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="../scripts/jquery.quicksand.js"></script>
<script type="text/javascript" src="../scripts/jquery.easing.1.3.js"></script>
  • Only tested with iPhone so I don't know if all devices < 500 ignore javascript like this. 仅在iPhone上进行过测试,因此我不知道是否所有<500的设备都不会像这样忽略javascript。

A script that triggers an error would disable all the following scripts in the page. 触发错误的脚本将禁用页面中的以下所有脚本。

probably you are executing some code that relies in jQuery or other library, that is not loaded yet, or simply you have some slight error that you didn't notice. 可能您正在执行一些依赖jQuery或其他库的代码,但尚未加载,或者只是有些轻微的错误,您没有注意到。

Did you try to put that code after all the linked scripts, and just check if it gets there? 您是否尝试过将这些代码放在所有链接的脚本之后,只是检查它是否到达那里?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="../scripts/jquery.prettyPhoto.js"></script>
<script type="text/javascript" src="../scripts/jquery.quicksand.js"></script>
<script type="text/javascript" src="../scripts/jquery.easing.1.3.js"></script>

<script>
if ( screen.availWidth > 500 ) {
    alert("Hello!");
};
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM