javascript脚本无法正常工作并崩溃IE [英] javascript script not working and crashing IE

查看:150
本文介绍了javascript脚本无法正常工作并崩溃IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Felix Kling在这篇文章中提供了这个脚本 HERE ,但是当我使用它时崩溃我的IE;在FF 3.6上,Opera,Chrome,Safari工作正常。

I have this script provided by @Felix Kling in this post HERE, but is crashing my IE when I use it; on FF 3.6, Opera, Chrome, Safari work fine.

知道为什么会这样吗?修复可能吗?

Any idea why is this happening? A fix maybe?

var ajaxTimeout;

function autorun() {
    if ($("#contactForm").is(":visible")){
        if(ajaxTimeout) {
            clearInterval(ajaxTimeout);
            ajaxTimeout = false;
        }
    }
    else if(!ajaxTimeout) {
        ajaxTimeout = setInterval("refreshAjax();", 15000);
    }
}


$(function autorun() {
    setInterval("autorun();", 2000)
});

谢谢,

Cristian。

LE。对不起,忘了添加有关它的详细信息。

LE. Sorry, forgot to add details about that.

IE只是关闭,遇到错误,需要关闭,寻找解决方案......。 IE 8.0 Windows7。如果我加载页面,我无法从开发人员工具打开调试器,但是如果我在加载该页面之前打开调试器并按启动调试它没有显示任何错误或任何内容,但页面没有刷新网格它是假设的。

IE just closes, "encounter an error and needs to close, looking for a solution ...". IE 8.0 Windows7. If I load the page, I cannot open the debugger from the developer tools, but if I open the debugger before I load that page and press Start debug it doesn't show any errors or anything, but the page is not refreshing the grid as it was suppose to.

推荐答案

以下是您的追求:

$(function () {
  var ajaxTimeout;
  function autorun() {
    if ($("#contactForm").is(":visible")){
      if(ajaxTimeout) {
        clearInterval(ajaxTimeout);
        ajaxTimeout = false;
      }
    }
    else if(!ajaxTimeout) {
      ajaxTimeout = setInterval(refreshAjax, 15000);
    }
  }
  setInterval(autorun, 2000);
});

IE完全不像这样使用的命名函数,它覆盖了之前定义的函数。 这是一个长期存在的错误不是修复到IE9 。问题的核心是 $(函数autorun(){正在接管 autorun 这个名字,这只是排队越来越多的自己。

IE doesn't at all like named functions used like this, and it's overriding the previously defined one. This is a long-standing bug not fixed until IE9. The core of the problem is that $(function autorun() { is taking over the autorun name, which is just queuing more and more runs of itself.

此外,最好将函数引用传递给 setInterval() 直接,而不是字符串。

Also, it's better to pass function references to setInterval() directly, not strings.

这篇关于javascript脚本无法正常工作并崩溃IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆