为什么Dojo 1.9 / JS代码不能在Internet Explorer 7中运行? [英] Why doesn't this Dojo 1.9/JS code work in Internet Explorer 7?

查看:131
本文介绍了为什么Dojo 1.9 / JS代码不能在Internet Explorer 7中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们对使用Dojo 1.9的Web应用程序有问题。该应用程序在Chrome,Firefox和IE 10/11中正常工作,但我们正在获取IE 7中的问题报告。

We are having a problem with a web application that uses Dojo 1.9. The application works fine in Chrome, Firefox and IE 10/11 but we are getting reports of a problem in IE 7.

UNFORTUNATELY ,I没有办法直接测试,因为根据公司指令,IE 7已从所有开发者机器中删除。所以我负责修复一个我无法复制的错误。

UNFORTUNATELY, I have no way to test this directly because by corporate directive, IE 7 was removed from all developer machines. So I am responsible for fixing a bug I have no way to duplicate.

由于用户反馈,应用程序中的所有按钮都从type =submit更改为type =button,并将onclick()处理程序添加到按钮,以便当按钮被点击时,窗体将仅提交 ,而按ENTER键则不会。这是dojo / domReady!连接按钮的代码:

Because of user feedback, all the buttons in the application were changed from type="submit" to type="button" and an onclick() handler was added to the buttons so that the form would be submitted only when the button was clicked but not when ENTER was pressed. Here is the dojo/domReady! code that wires the buttons:

    //  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)的例程:

Here is the routine that actually submits the form (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的人都可以在此代码中找到问题?感谢提前...

Can anybody familiar with IE7 spot the problem in this code? Thanks in advance...

推荐答案

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

Short Answer: IE7 and Spring Web Flow are not compatible.

长回答:

不仅 Dojo 1.9不支持IE 7 ,但IE7原来是

Not only does Dojo 1.9 not support IE 7, but IE7 turns out to be very problematic with Spring Web Flow. Because IE7 submits all buttons to the server, regardless of what button is clicked, it is a hassle to pass Web Flow events back to the server using IE7 and required a very ugly 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();

这个黑客基本上从表单中删除了所有的按钮对象,然后添加了一个按钮实际上被点击为隐藏字段,然后提交表单。

This hack basically rips out all the button objects from the form, then adds back the one button that was actually clicked as a hidden field, and then submits the form.

这篇关于为什么Dojo 1.9 / JS代码不能在Internet Explorer 7中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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