By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

Problem with window opener in IE

P: n/a
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
Oct 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Soren Schimkat <sc******@noemail.hum.aau.dk> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Oct 20 '05 #2

P: n/a
[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

Oct 21 '05 #3

P: n/a
[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

Oct 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.