使用Javascript w/Prototype在IE8中“不能执行从*脚本中执行的代码”。

时间:2021-07-13 04:34:51

This is my first question on here so here goes....

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

I've got an issue in IE8 where I have a popup form (window.showDialog()) used to edit receipt information in an accounting system.

我在IE8中有一个问题,我有一个弹出式表单(window.showDialog()),用于在一个会计系统中编辑接收信息。

This was working fine up until I had to add more content by adding a dynamically built table of input fields. I'm getting the information back in an array, however that's where my error seems to be occurring. var pinputs = []; is what seems to be causing the issue.

在我添加更多内容之前,我必须添加一个动态构建的输入字段表。我在数组中获取信息,但这是我的错误发生的地方。var pinput =[];是什么导致了这个问题。

js function in the popup form:

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 function in the parent js file:

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");
}

I found a similar situation already on here but that was involving the calling of functions from the child form which I'm not doing here. Perhaps I didn't understand the solution? I'm not an expert with JS so any input will be helpful.

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

--Edit--

——编辑

Forgot to also add in here that the var payments = $$('.payment'); is the array of input fields in my template file.

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

2 个解决方案

#1


4  

You're probably trying to access methods on the array returned by the popup after the popup is closed. That returned array was constructed on the popup, and is dependent on the popup still existing to be usable.

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

So you have a few options:

所以你有几个选择:

  • don't close the popup from within the popup script. Get your parent handler to do what it needs with the array (such as cloning it in an array of its own with [].concat(popupArray) for example), then have it close the popup.

    不要在弹出的脚本中关闭弹出窗口。让您的父处理程序在数组中执行它所需要的操作(例如,将它与[].concat(generparray)的数组一起克隆),然后关闭弹出窗口。

  • convert your array to a string to cross the popup/parent boundary. JSON.stringify()/JSON.parse() would do the job nicely if you don't care about IE6/7. That way, you can still close the popup from within the popup script (apparently, string objects don't get that particular problem with IE.)

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

#2


4  

I had the same problem, so I wrote this handy function to work around the issue.

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

// 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;
}

Then you can use it thusly:

然后你可以使用它:

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

#1


4  

You're probably trying to access methods on the array returned by the popup after the popup is closed. That returned array was constructed on the popup, and is dependent on the popup still existing to be usable.

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

So you have a few options:

所以你有几个选择:

  • don't close the popup from within the popup script. Get your parent handler to do what it needs with the array (such as cloning it in an array of its own with [].concat(popupArray) for example), then have it close the popup.

    不要在弹出的脚本中关闭弹出窗口。让您的父处理程序在数组中执行它所需要的操作(例如,将它与[].concat(generparray)的数组一起克隆),然后关闭弹出窗口。

  • convert your array to a string to cross the popup/parent boundary. JSON.stringify()/JSON.parse() would do the job nicely if you don't care about IE6/7. That way, you can still close the popup from within the popup script (apparently, string objects don't get that particular problem with IE.)

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

#2


4  

I had the same problem, so I wrote this handy function to work around the issue.

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

// 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;
}

Then you can use it thusly:

然后你可以使用它:

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