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. Advertising

  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. Advertising

  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. Advertising

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. 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,082
    Andrew Bewley via DotNetMonster.com
    Feb 3, 2005
  2. Urs Gubler
    Replies:
    0
    Views:
    162
    Urs Gubler
    Jul 2, 2003
  3. Yaron C.

    opener.opener ?

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

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

Share This Page