Heim  >  Artikel  >  Web-Frontend  >  defer属性导致引用JQuery的页面报“浏览器无法打开网站xxx,操作被中止”错误的解决方法_javascript技巧

defer属性导致引用JQuery的页面报“浏览器无法打开网站xxx,操作被中止”错误的解决方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 18:28:401273Durchsuche

在一个aspx页面中使用了JQuery,但当IE6浏览器打开这个页面的时候会报“Internet Explorer cannot open the Internet site http://localhost:9001/Index.aspx. Operation aborted”的错误,然后就不能正常浏览此页面。如果使用IE7或者IE8就没有此问题。
Operationaborted

将所有的js脚本都使用“”标记注释掉(这样虽然会导致问题,但至少可以浏览此页面)。逐个检查后发现了问题所在:

复制代码 代码如下:





是这行语句引起的问题,注释此行后页面就能正常浏览了。

查询发现是引用的js脚本操作了某个尚未载入的页面元素,这样就很好解决问题,为<script>脚本添加”defer”属性之后,页面可以正常浏览了。 <br><br><div class="codetitle"><span><a style="CURSOR: pointer" data="93027" class="copybut" id="copybut93027" onclick="doCopy('code93027')"><U>复制代码 代码如下:<div class="codebody" id="code93027"> <BR><script defer="defer" src="Jquery/DatePicker/WdatePicker.js" type="text/javascript"></script>


参考资料:

Script中的Defer属性
如果你是一个对系统性能比较关心和在意的人,我想你应该会对Script脚本中的defer属性感兴趣的。
script中的defer属性默认情况下是false的。按照DHTML编程宝典中的描述,对于Defer属性是这样写的:
Using the attribute at design time can improve the download performance of a page because the browser does not need to parse and execute the script and can continue downloading and parsing the page instead.
也就是说:如果是编写脚本的时候加入defer属性,那么浏览器在下载脚本的时候就不必立即对其进行处理,而是继续对页面进行下载和解析,这样会提高下载的性能。
这样的情况有很多种。比如你定义了很多javascript变量,或者在引用文件(.inc)中写了很多的脚本需要处理,那不妨在这些脚本中加入defer属性,对性能的提高肯定有所帮助。
举例如下:

因为defer属性默认是为false的,那么在这里
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn