Problem with window opener in IE

Discussion in 'Javascript' started by Soren Schimkat, Oct 20, 2005.

  1. 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
     
    Soren Schimkat, Oct 20, 2005
    #1
    1. Advertisements

  2. Soren Schimkat <> 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 -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Oct 20, 2005
    #2
    1. Advertisements

  3. [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
     
    Soren Schimkat, Oct 21, 2005
    #3
  4. [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
     
    Soren Schimkat, Oct 21, 2005
    #4
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Wark
    Replies:
    3
    Views:
    6,813
    bruce barker
    Oct 28, 2004
  2. =?Utf-8?B?Sko=?=
    Replies:
    1
    Views:
    2,439
    =?Utf-8?B?dmluYXk=?=
    Oct 12, 2004
  3. Andrew Bewley via DotNetMonster.com

    window to window communication (window.opener)

    Andrew Bewley via DotNetMonster.com, Feb 3, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,281
    Andrew Bewley via DotNetMonster.com
    Feb 3, 2005
  4. =?Utf-8?B?TXJGZXo=?=

    Child window property window.opener null after postback

    =?Utf-8?B?TXJGZXo=?=, Apr 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    5,952
    =?Utf-8?B?TXJGZXo=?=
    Apr 28, 2005
  5. Urs Gubler
    Replies:
    0
    Views:
    302
    Urs Gubler
    Jul 2, 2003
  6. Yaron C.

    opener.opener ?

    Yaron C., Oct 30, 2003, in forum: Javascript
    Replies:
    4
    Views:
    377
    Yaron C.
    Nov 2, 2003
  7. atlas
    Replies:
    1
    Views:
    209
    Martin Honnen
    Sep 7, 2005
  8. window.opener, form.opener?

    , Jul 14, 2006, in forum: Javascript
    Replies:
    5
    Views:
    480
Loading...