【问题标题】:Why doesn't this Dojo 1.9/JS code work in Internet Explorer 7?为什么这个 Dojo 1.9/JS 代码在 Internet Explorer 7 中不起作用?
【发布时间】:2014-07-03 04:41:04
【问题描述】:

我们遇到了一个使用 Dojo 1.9 的 Web 应用程序的问题。该应用程序在 Chrome、Firefox 和 IE 10/11 中运行良好,但我们收到了有关 IE 7 中的问题的报告。

不幸的是,我无法直接对此进行测试,因为根据公司指令,IE 7 已从所有开发人员机器中删除。所以我负责修复一个我无法复制的错误。

由于用户反馈,应用程序中的所有按钮都从 type="submit" 更改为 type="button" 并且在按钮中添加了 onclick() 处理程序,以便仅提交表单 在单击按钮时,但在按下 ENTER 时不会。这里是 dojo/domReady!连接按钮的代码:

    //  Make the buttons submit the form ONLY on click (avoid keypress)
    query("button[type='button']").on("click", function(e) {
        console.log("    in button onclick handler");
        //  This actually submits the form based on the button that was clicked
        myapp.core.buttonClick("applicationInfo",this);
        console.log("    leaving button onclick handler");
    })

这里是实际提交表单的例程(myapp.core.buttonClick):

    myapp.core.buttonClick = function(formName, buttonObject) {
        // Have to do this to transmit the data - the button info
        // won't be transmitted otherwise
        var formObject = document.forms[formName];
        var newField = document.createElement('input');
        newField.type = 'hidden';
        newField.name = buttonObject.name;
        newField.value = buttonObject.value;
        formObject.appendChild(newField);
        formObject.submit();
    }

任何熟悉 IE7 的人都可以在这段代码中发现问题吗?提前谢谢...

【问题讨论】:

  • 你试过BrowserStack这样的服务吗? browserstack.com
  • 是的,我已经在 BrowserStack 中尝试过并验证它失败了,但是 BrowserStack 上可用的工具不足以让我识别它失败的地方。这是一个 catch-22 - 我可以在 Browserstack 上看到它发生但不能调试它,我可以在本地调试它但不会使错误发生。
  • 听起来很奇怪,但是用警报更改console.logs 怎么样(在暂存环境中,所以您不会实时推送)?
  • 手动老式调试,嗯?值得一试......
  • 根据发行说明,Dojo 1.9x 不支持 IE7 [dojo-toolkit.33424.n3.nabble.com/…dojotoolkit.org/reference-guide/1.9/releasenotes/1.9.html 我的 2 美分。可能是dojo.on模块在IE7上不工作的问题,你能不能试试旧的dojo.connect模块,看看它是否工作。

标签: javascript html internet-explorer dojo


【解决方案1】:

简答:IE7 和 Spring Web Flow 不兼容。

长答案:

不仅Dojo 1.9 not support IE 7,而且IE7 原来是very problematic with Spring Web Flow。因为 IE7 将所有按钮提交给服务器,无论点击哪个按钮,使用 IE7 将 Web Flow 事件传回服务器是一件很麻烦的事情,并且需要一个非常丑陋的 hack:

var formObject = document.forms[formName];
//  Rip out the buttons because IE7 sucks
for (i=0;i<formObject.length;i++) {
    if (formObject[i].tagName === 'BUTTON') {
        formObject[i].parentNode.removeChild(formObject[i]);
        i--;
    }
}
var newField = document.createElement('input');
newField.type = 'hidden';
newField.id=buttonObject.id;
newField.name = buttonObject.name;
if (buttonObject.attributes['value'] != null) {
    newField.value = buttonObject.attributes['value'].value;
} else {
    newField.value = buttonObject.value;
}
formObject.appendChild(newField);
formObject.submit();

这个 hack 基本上是从表单中删除所有按钮对象,然后将实际单击的 一个按钮 作为隐藏字段添加回来,然后提交表单。

【讨论】:

    猜你喜欢
    • 2011-11-19
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 2012-06-07
    相关资源
    最近更新 更多