window.open then onload function

Discussion in 'Javascript' started by Richard Bell, Oct 20, 2004.

  1. Richard Bell

    Richard Bell Guest

    I'm a bit new to Javascript and am trying to do

    oNewWin = window.open( ... );

    then determine when the contents of oNewWin are completely loaded.

    I've tried

    oNewWin.attachEvent( "onload", myfunc);

    but that doesn't work.

    Can something of this sort be done?
     
    Richard Bell, Oct 20, 2004
    #1
    1. Advertising

  2. Richard Bell

    Grant Wagner Guest

    Richard Bell wrote:

    > I'm a bit new to Javascript and am trying to do
    >
    > oNewWin = window.open( ... );
    >
    > then determine when the contents of oNewWin are completely loaded.
    >
    > I've tried
    >
    > oNewWin.attachEvent( "onload", myfunc);
    >
    > but that doesn't work.
    >
    > Can something of this sort be done?


    Create a dummy document as follows:

    --dummy.html--
    <html>
    <head>
    <title>dummy.html</title>
    </head>
    <body onload="
    if (window.opener && window.opener.callBack) {
    window.opener.callBack();
    }
    ">
    </body>
    </html>

    Then structure your script to open the new window as follows:

    <script type="text/javascript">
    function callBack() {
    alert('The new window has finished loading!');
    }
    oNewWin = window.open('dummy.html', 'theName', '...');
    </script>

    If you don't like the idea of creating dummy.html on your file system,
    you could use:

    var newDocument = [
    '<html>',
    '<head>',
    '<title>dummy.html</title>',
    '</head>',
    '<body',
    ' onload="if (window.opener && window.opener.callBack)',
    ' window.opener.callBack();">',
    '</body>',
    '</html>'
    ].join('\n');
    oNewWin = window.open('javascript:newDocument', 'theName', '...');

    All the usual warnings about popups apply (they may not be available,
    they may be available but not do what you expect, they may open as new
    tabs in an existing browser window, etc).

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
     
    Grant Wagner, Oct 20, 2004
    #2
    1. Advertising

  3. Richard Bell

    Richard Bell Guest

    On Wed, 20 Oct 2004 17:06:20 GMT, Grant Wagner
    <> wrote:


    >Create a dummy document as follows:
    >
    >--dummy.html--
    ><html>
    ><head>
    ><title>dummy.html</title>
    ></head>
    ><body onload="
    > if (window.opener && window.opener.callBack) {
    > window.opener.callBack();
    > }
    >">
    ></body>
    ></html>
    >
    >Then structure your script to open the new window as follows:
    >
    ><script type="text/javascript">
    >function callBack() {
    > alert('The new window has finished loading!');
    >}
    >oNewWin = window.open('dummy.html', 'theName', '...');
    ></script>


    Unfortunately, I need to load an arbitrary URL that I've no control
    over, thus I was hoping to sit on the child window's onload event or
    something similar. I did find a frame approach that works for many,
    but alas not all ... about a 6% failure rate, URLs and am searching
    for a more robust solution.

    Is anyone aware of an approach that doesn't depend on frames or having
    access to the childs HTML content?

    In a somewhat related question, how do I tell that the child has
    created a child (popup) window of its own?

    Thanks

    >
    >If you don't like the idea of creating dummy.html on your file system,
    >you could use:
    >
    >var newDocument = [
    > '<html>',
    > '<head>',
    > '<title>dummy.html</title>',
    > '</head>',
    > '<body',
    > ' onload="if (window.opener && window.opener.callBack)',
    > ' window.opener.callBack();">',
    > '</body>',
    > '</html>'
    >].join('\n');
    >oNewWin = window.open('javascript:newDocument', 'theName', '...');
    >
    >All the usual warnings about popups apply (they may not be available,
    >they may be available but not do what you expect, they may open as new
    >tabs in an existing browser window, etc).
     
    Richard Bell, Oct 20, 2004
    #3
    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. Fabio R.
    Replies:
    0
    Views:
    820
    Fabio R.
    Mar 25, 2005
  2. Replies:
    0
    Views:
    312
  3. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    585
    Martin Honnen
    Nov 4, 2004
  4. Q
    Replies:
    7
    Views:
    136
  5. Replies:
    2
    Views:
    409
Loading...

Share This Page