Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Problem with window opener in IE

Reply
Thread Tools

Problem with window opener in IE

 
 
Soren Schimkat
Guest
Posts: n/a
 
      10-20-2005
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
 
Reply With Quote
 
 
 
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      10-20-2005
Soren Schimkat <(E-Mail Removed)> 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 - http://www.velocityreviews.com/forums/(E-Mail Removed)
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 
Reply With Quote
 
 
 
 
Soren Schimkat
Guest
Posts: n/a
 
      10-21-2005
[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

 
Reply With Quote
 
Soren Schimkat
Guest
Posts: n/a
 
      10-21-2005
[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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
window.opener, form.opener? jojowebdev@gmail.com Javascript 5 07-14-2006 07:08 PM
Problem with window.opener AND window.name IN firefox atlas Javascript 1 09-07-2005 05:30 PM
window to window communication (window.opener) Andrew Bewley via DotNetMonster.com ASP .Net 0 02-03-2005 12:59 PM
opener.opener ? Yaron C. Javascript 4 11-02-2003 06:11 AM
trigger event on opener from popup when closing it or run opener script from popup Urs Gubler Javascript 0 07-02-2003 02:08 PM



Advertisments