window.open then onload function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Bell

    window.open then onload function


    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.attachE vent( "onload", myfunc);

    but that doesn't work.

    Can something of this sort be done?



  • Grant Wagner

    #2
    Re: window.open then onload function

    Richard Bell wrote:
    [color=blue]
    > 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.attachE vent( "onload", myfunc);
    >
    > but that doesn't work.
    >
    > Can something of this sort be done?[/color]

    Create a dummy document as follows:

    --dummy.html--
    <html>
    <head>
    <title>dummy.ht ml</title>
    </head>
    <body onload="
    if (window.opener && window.opener.c allBack) {
    window.opener.c allBack();
    }
    ">
    </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('du mmy.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.h tml</title>',
    '</head>',
    '<body',
    ' onload="if (window.opener && window.opener.c allBack)',
    ' window.opener.c allBack();">',
    '</body>',
    '</html>'
    ].join('\n');
    oNewWin = window.open('ja vascript:newDoc ument', '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 <gwagner@agrico reunited.com>
    comp.lang.javas cript FAQ - http://jibbering.com/faq

    Comment

    • Richard Bell

      #3
      Re: window.open then onload function

      On Wed, 20 Oct 2004 17:06:20 GMT, Grant Wagner
      <gwagner@agrico reunited.com> wrote:

      [color=blue]
      >Create a dummy document as follows:
      >
      >--dummy.html--
      ><html>
      ><head>
      ><title>dummy.h tml</title>
      ></head>
      ><body onload="
      > if (window.opener && window.opener.c allBack) {
      > window.opener.c allBack();
      > }
      >">
      ></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('du mmy.html', 'theName', '...');
      ></script>[/color]

      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
      [color=blue]
      >
      >If you don't like the idea of creating dummy.html on your file system,
      >you could use:
      >
      >var newDocument = [
      > '<html>',
      > '<head>',
      > '<title>dummy.h tml</title>',
      > '</head>',
      > '<body',
      > ' onload="if (window.opener && window.opener.c allBack)',
      > ' window.opener.c allBack();">',
      > '</body>',
      > '</html>'
      >].join('\n');
      >oNewWin = window.open('ja vascript:newDoc ument', '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).[/color]

      Comment

      Working...