开发者

Child window access an array from parent window is not working in IE, but works in Firefox, how to fix?

I have a index.html page which has a button (id="my-btn"):

<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>My INDEX PAGE</title>
    </head>
    <body>
        <br><input type="button" id="my-btn" value="OPEN NEW WINDOW"/>
        <script src="js/my.js"></script>
    </body>
    </html>

The index page included my.js which is used to handle button click event, when button is clicked, a new browser window(child window) will be opened with a new page(new.html)

js/my.js:

$('#my-btn').click(function(){  
  var childWin = window.open('new.html', '');
  childWin.parentElements=[1,2,3];
});

as you noticed above, I passed an array [1,2,3] to the new opened child window.

The new page (new.html) opened in a new browser window(child window):

new.html:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TEST</title>
</head>
<body>
    <div id="my-arr"></div>
    <script src="js/jquery-1.5.1.js"></script>
    <script src="js/new.js"></script>

</body>
</html>

In the new page, new.js is included which will append the text of the array passed from parent window as the content of this page in child window.

js/new.js:

$(document).ready(function(){
    var arr= window.parentElements;

for(var i=0; i<arr.length; i++){
    var el = arr[i];
    $('#my-arr').append("<strong>"+el+"</strong>");
}

});

Everything is working in Firefox (I got the array in the new child window page).

BUT when I test it in IE 7, it does not work, in the new popped up page, IE shows an error =>"Length" is null or 开发者_运维问答not an object which complain about "elements.length" in new.js. It seems IE does not support pass data in this way childWin.parentElements=[1,2,3]

How to make this code working in IE?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜