javascript - JSON Object returned from a second page does not stringify in IE 8 -
consider next scenario:
foopage page which, on clicking "add", opens barpage.
barpage has "return" button. upon clicking on it, following:
function add() { var selectedresources = [{ "resourceid": "10", "resourcename": "foo", "resourcetypename": "bar" }]; if (window.opener != null && typeof window.opener.addresources != "undefined") { window.opener.addresources(selectedresources); window.close(); } }
foopage, may see, has function called addresources
. following:
function addresourcescallback(selectedresources) { var result = json.stringify(selectedresources); }
in chrome, works great - string created json in json.stringify
, happy.
in ie8, however, not work. json not created string - instead, json.stringify
returns undefined
.
i tried changing scenario this, test:
function addresourcescallback(selectedresources) { var selectedresources = [{ "resourceid": "10", "resourcename": "foo", "resourcetypename": "bar" }]; var result = json.stringify(selectedresources); }
in scenario, json.stringify
in ie8 returns right value, chrome. meaning, in ie8, when passing array page page, can't parse array json.
is there way pass array without stringifying first?
seems cross-window scope problem - 2 objects have different object.prototype
prototype objects might confuse ie (especially if 1 of them garbage collected due window closing). seek stringifying other window's json
function this:
// barpage if (window.opener != null && typeof window.opener.addresources != "undefined") { window.opener.addresources(selectedresources, json); window.close(); } // foopage function addresourcescallback(selectedresources, json) { var result = json.stringify(selectedresources)); }
however, think stringifying in 1 window, passing string , parsing in other window safest approach.
javascript json internet-explorer-8
No comments:
Post a Comment