Problem with window opener in IE

S

Soren Schimkat

Hi

This works fine and adds a new element to the list:


document.forms['formname'].elements['listname'].options[0] = new
Option('foo', 'bar');


... but using the following code in a popup window - IE crashes or tells
me that the server threw an exception:


window.opener.document.forms['formname'].elements['listname'].options[0]
= new Option('foo', 'bar')


The code works just fine in Firefox. Could someone give me at hint on
what's wrong here?

Kind regards Søren
 
L

Lasse Reichstein Nielsen

Soren Schimkat said:
IE crashes or tells me that the server threw an exception:

window.opener.document.forms['formname'].elements['listname'].options[0]
= new Option('foo', 'bar')

The code works just fine in Firefox. Could someone give me at hint on
what's wrong here?

Probably that you are adding an instance of Option from the current
document to a select from another document. I would try using the "Option"
constructor function from the other window, i.e., something like:

var otherWindow = window.opener;
otherWindow.document.forms['formname'].elements['listname'].options[0] =
new otherWindow.Options('foo','bar');

Not sure whether it works, though. My tests are inconclusive :)


To avoid this cross-page DOM scripting, you could put a function on the
original page to do the work, and just call it from the opened page.

<script type="text/javascript">
function addOption(text,value) {
document.forms['formname'].elements['listname'].options[0] =
new Option(text,value);
}
</script>

and then just do
window.opener.addOption('foo','bar');
in the opened window.
/L
 
S

Soren Schimkat

[snip]
To avoid this cross-page DOM scripting, you could put a function on the
original page to do the work, and just call it from the opened page.


yes offcourse .. that's the way to do. It works fine now. :)

Tak for hjælpen.

mvh Søren

<script type="text/javascript">
function addOption(text,value) {
document.forms['formname'].elements['listname'].options[0] =
new Option(text,value);
}
</script>

and then just do
window.opener.addOption('foo','bar');
in the opened window.
/L
 
S

Soren Schimkat

[snip]
To avoid this cross-page DOM scripting, you could put a function on the
original page to do the work, and just call it from the opened page.


yes offcourse .. that's the way to do. It works fine now. :)

Tak for hjælpen.

mvh Søren

<script type="text/javascript">
function addOption(text,value) {
document.forms['formname'].elements['listname'].options[0] =
new Option(text,value);
}
</script>

and then just do
window.opener.addOption('foo','bar');
in the opened window.
/L
 

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,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top