Accessing constructors from child windows, IE

A

Arnaud Diederen

Hi,

[I've checked the archives, found some postings that were more or less
related to my problem, but couldn't find a satisfying answer.]

Let's say I have a webapp 'root' window into which I include all
my important JavaScript, including functions that I use as
constructors. Let's say I have a 'class' whose constructor is
'Konstructor'. (weird name, but it's only for the example)

If, from this root window, I create a new window
(window.open('./subwin.html')), I can access the code of the
constructor (with: window.opener[.top].Konstructor), but I cannot
execute a "new window.opener[.top].Konstructor (args)", because IE
complains about an invalid function call.

(IE has this problem, Mozilla runs the code fine. Other browsers
untested)

Has anyone any idea about this?
What prevents me from doing so?
Is it improper JS?
Any pointer/idea where to look?

Thanks much for any information you could provide :)

Best regards,

Arnaud





Follows: A test-case that works w/ Mozilla, and fails w/ IE:

==================================================
root.html:

<html>
<head><title>test scope</title></head>
<body>
<script>
function Konstructor (str) {

alert ("Kreated new Konstructor Obj w/ str : " + str);
}
</script>

<input type="button"
onclick="new Konstructor('button clicked')"
value="Click here to test local creation of stuff"
/>
<input type="button"
onclick="window.open ('./childWin.html', 'child');"
value="Click here to launch a window that'll try and create a Ktor object"
/>
</body>
</html>

==================================================
childWin.html:

<html>
<head><title>test scope (subwin)</title></head>
<body>

Hello there!
<script>
alert ("Function code is :" + window.opener.top.Konstructor);
new window.opener.top.Konstructor ("From child!");
</script>

</body>
</html>
 
V

VK

Arnaud said:
Hi,

[I've checked the archives, found some postings that were more or less
related to my problem, but couldn't find a satisfying answer.]

Let's say I have a webapp 'root' window into which I include all
my important JavaScript, including functions that I use as
constructors. Let's say I have a 'class' whose constructor is
'Konstructor'. (weird name, but it's only for the example)

If, from this root window, I create a new window
(window.open('./subwin.html')), I can access the code of the
constructor (with: window.opener[.top].Konstructor), but I cannot
execute a "new window.opener[.top].Konstructor (args)", because IE
complains about an invalid function call.

(IE has this problem, Mozilla runs the code fine. Other browsers
untested)

Yes, it seems that IE implements "current window" scope for constructor
members, and Firefox doesn't. It is a such twilight zone though that it
is really difficult to say whos right and whos wrong here. No one gave
any official promises yet.

The only idea I can come up with is to use a transport packager like:

<html>
<head>
<title>test scope</title>
<script type="text/javascript">
var w = null;

var obj1 = null;

function Proto(str) {
this.message = str;
alert('Created new Proto object with field value: '+this.message);
}

function ProtoDelivery(str) {
return new Proto(str);
}
</script>
</head>
<body>
<input type="button"
onclick="obj1=new Proto('button clicked');"
value="Click here to test local creation of stuff"
/>
<input type="button"
onclick="w=window.open('childWin.html','child');"
value="Click here to launch a window that'll try and create a
Proto object"
/>
</body>
</html>

--------------------------------------
-------------------------------------

<html>
<head>
<title>test scope (subwin)</title>
<script type="text/javascript">
var a;
function test() {
alert ("Function code is :" + window.opener.Proto.toString());
// This stops the error but just silently ignored:
//var f = new Function();
//f.constructor = window.opener.Proto.constructor;
a = window.opener.ProtoDelivery('From child!');
alert(a.message);
}
window.onload = test;
</script>
</head>
<body>
<p>Hello there!</p>
</body>
</html>
 
A

Arnaud Diederen

VK said:
The only idea I can come up with is to use a transport packager like:

[...]

function Proto(str) {
this.message = str;
alert('Created new Proto object with field value: '+this.message);
}
function ProtoDelivery(str) {
return new Proto(str);
}

[...]

window.opener.ProtoDelivery('From child!');


Yes, that's the only way I can work around that problem, so far :)


Regards,
Arnaud
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top