【问题标题】:jQuery dialog + iframe gives this error in IE9: SCRIPT5009: 'Array' is undefinedjQuery 对话框 + iframe 在 IE9 中出现此错误:SCRIPT5009: 'Array' is undefined
【发布时间】:2023-03-15 23:20:02
【问题描述】:

我一直在与一个只有 IE9 才会遇到的错误作斗争。根据 jQuery 和 jQuery-UI 的版本,错误消息会有所不同。使用 jquery 1.8.3 和 jquery-ui 1.8.24,我会收到以下错误消息:

SCRIPT5009:“数组”未定义

但是,使用 jquery 1.7.x 和 jquery-ui 1.7.x,我会收到以下错误消息:

SCRIPT5009:“对象”未定义

这是违规页面的代码:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.8.24/jquery-ui.min.js"></script>
<title></title>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#dialog").dialog();
        });
    </script>
</head>
<body>
    <div id="dialog">
        <iframe id="iframe1" src="jqtest2.htm"></iframe>
    </div>
</body>
</html>

这是该页面中 iframe 的代码:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
</head>
<body>
</body>
</html>

在使用兼容性视图模式的 IE 9、Google Chrome 或 Firefox 中,我没有收到这些错误消息。

iframe 中包含 jquery 似乎是罪魁祸首。

【问题讨论】:

    标签: jquery iframe internet-explorer-9


    【解决方案1】:

    这是我解决问题的方法。我将 iframe src 属性留空,并且仅在调用 dialog() 之后才使用 jquery 对其进行初始化。我想,这样 IE 稍后会加载 iframe 内容,在这种情况下,问题不会出现。这是修改后的代码:

    <!DOCTYPE html>
    <html>
    <head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.8.24/jquery-ui.min.js"></script>
    <title></title>
        <script type="text/javascript">
            $(document).ready(function() {
                $("#dialog").dialog();
                $("#iframe1").attr("src", "jqtest2.htm");
            });
        </script>
    </head>
    <body>
        <div id="dialog">
            <iframe id="iframe1" src=""></iframe>
        </div>
    </body>
    </html>
    

    iframe html 文件保持不变。

    【讨论】:

    • 这是一个很好的解决方案,即使不涉及对话内容也能正常工作。谢谢!
    【解决方案2】:
    function waitForjQuery(){
        if(typeof jQuery!='undefined'){
            //Do yor stuff!
        }
        else{
            setTimeout(function(){
                waitForjQuery();
            },500);
        }
    }
    waitForjQuery();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-06
      • 1970-01-01
      相关资源
      最近更新 更多