0

From showmodaldialog window.returnValue in Firefox I am getting array object, but in IE and Chrome getting error.

function doYes() {
    var val=[];
    val.push("A");
    val.push("B");
    window.returnValue =val;
}

Even array works in Firefox not in IE9. Please see the piece of code in showModalDialog box.

function doYes() {
    var val={};
    val.x="A";
    val.y="B";
    window.returnValue =val;
}

This also works in Firefox not in IE9.

Teemu
  • 22,918
  • 7
  • 53
  • 106
  • 1
    Please share a bit of code, or (preferably) a functional demo. – Sampson Dec 20 '14 at 18:59
  • function doYes() { var val=[]; val.push("A"); val.push("B"); window.returnValue =val; } Even array works in firefox not in IE9.. please see the piece of code in showModalDialog box. function doYes() { var val={}; val.x="A"; val.y="B"; window.returnValue =val; } This also works in firefox not in IE9.. please see the piece of code in showModalDialog box. – Vijay Marudhachalam Dec 24 '14 at 13:17
  • Please [edit] your question to add your code. – Sampson Dec 25 '14 at 02:20
  • I can't see any reason why these code snippets wouldn't work in IE. What is the error you get? – Teemu Dec 26 '14 at 14:58
  • Can't execute code from a freed script error...or when i am trying to print in alert box its showing no value in alert box. – Vijay Marudhachalam Dec 28 '14 at 11:05
  • The error is coming from the page which opens the dialog, everything is explained in my answer below. Though it talks about IE11, this seems to happen in IE9 too. – Teemu Dec 29 '14 at 05:08

1 Answers1

1

Since Chrome37, showModalDialog has been obsoleted. If you're using older Chrome, please read this SO answer.

In IE11: If dialog's return value is either an array or an object, it can't access the properties in its prototype. This causes for example alert(modal_return_value) to fail and trigger SCRIPT5011 Can't execute code from a freed script error (alert uses toString() method in the prototype).

Somehow this is even understandable since the prototype actually is in a window, which was closed before you will access these properties. I'm not sure if this is a bug or an intended feature in IE11, but either way it's annoying.

You can access to the own properties of the returned object though. For example you can iterate through an array using a for loop, and even alert(modal_return_value[n]) would work.

Or you can create a new array from the return value, something like this:

var arr = showModalDialog('returnsArray.htm');
if (!arr) {/* Dialog cancelled, do something */}
arr = Array.prototype.splice.call(arr, 0);

In the last line we borrow the splice method of Array.prototype and create a new array from the returned array.

Community
  • 1
  • 1
Teemu
  • 22,918
  • 7
  • 53
  • 106
  • function doYes() { var val=[]; val.push("A"); val.push("B"); window.returnValue =val; } Even array works in firefox not in IE9.. please see the piece of code in showModalDialog box. – Vijay Marudhachalam Dec 24 '14 at 13:14