繁体   English   中英

使用Javascript w / Prototype在IE8中“无法从释放的脚本执行代码”

[英]“Can't execute code from a freed script” in IE8 using Javascript w/Prototype

这是我在这里的第一个问题,所以这里......

我在IE8中遇到了一个问题,我有一个弹出窗体( window.showDialog() )用于编辑会计系统中的收据信息。

这个工作正常,直到我不得不通过添加动态构建的输入字段表来添加更多内容。 我在数组中获取信息,但这就是我的错误似乎正在发生的地方。 var pinputs = []; 是什么似乎导致了这个问题。

弹出窗体中的js函数:

function saveForm() {
if($('user_id')){
    var user_id = $F('user_id');
} else {
    var user_id = 0;
}
var payments = $$('.payment');
var pinputs = [];
for(var i=0; i<payments.length; i++){
    pinputs.push($F(payments[i]));
}
window.returnValue = {received_of: $F('received_of'), user_id: user_id,
                    note: $F('note'), work_date: $F('work_date'), payment: pinputs};
window.close();
}

父js文件中的js函数:

function modifyReceiptInformation(id) {
return window.showModalDialog('mod.php?mod=receipts&mode=receipt_edit_popup&wrapper=no&receipt_id=' + id, 'Modify Receipt',"dialogWidth:600px;dialogHeight:500px");
}

我在这里已经发现了类似的情况,但这涉及从子表单调用函数,我在这里没有这样做。 也许我不明白解决方案? 我不是JS的专家,所以任何输入都会有所帮助。

- 编辑 -

忘了还在这里添加var payments = $$('.payment'); 是我的模板文件中的输入字段数组。

在弹出窗口关闭后,您可能正在尝试访问弹出窗口返回的数组上的方法。 返回的数组是在弹出窗口上构建的,并且依赖于仍然可用的弹出窗口。

所以你有几个选择:

  • 不要从弹出脚本中关闭弹出窗口。 让你的父处理程序用数组做它需要的东西(例如用[].concat(popupArray)克隆它自己的数组,然后让它关闭弹出窗口。

  • 将数组转换为字符串以跨越弹出/父边界。 如果您不关心IE6 / 7, JSON.stringify()/JSON.parse()可以很好地完成工作。 这样,您仍然可以从弹出脚本中关闭弹出窗口(显然,字符串对象不会在IE中遇到特定问题。)

我有同样的问题,所以我写了这个方便的功能来解决这个问题。

// The array problem is when modalDialogue return values are arrays.  The array functions
// such as slice, etc... are deallocated when the modal dialogue closes.  This is an IE bug.
// The easiest way to fix this is to clone yourself a new array out of the remnants of the old.
//
// @param[in] ary
//   The array, which has been passed back from a modal dialogue (and is broken) to clone
// @returns
//   A new, unbroken array.
function cloneArray(ary) {
    var i;
    var newAry = [];
    for(i=0; i<ary.length; i++){
        if(Object.prototype.toString.call(ary[i]) == '[object Array]') {
            newAry.push(cloneArray(ary[i]));
        } else{
            newAry.push(ary[i]);
        }
    }
    return newAry;
}

然后你可以这样使用它:

var selectedAry = window.showModalDialog("Window.jsp", inputAry, "dialogWidth:900px; dialogHeight:700px; center:yes; resizable: yes;");
var newAry = cloneArray(selectedAry);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM