Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > window.open then onload function

Reply
Thread Tools

window.open then onload function

 
 
Richard Bell
Guest
Posts: n/a
 
      10-20-2004

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?



 
Reply With Quote
 
 
 
 
Grant Wagner
Guest
Posts: n/a
 
      10-20-2004
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 <(E-Mail Removed)>
comp.lang.javascript FAQ - http://jibbering.com/faq

 
Reply With Quote
 
 
 
 
Richard Bell
Guest
Posts: n/a
 
      10-20-2004
On Wed, 20 Oct 2004 17:06:20 GMT, Grant Wagner
<(E-Mail Removed)> 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).


 
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
onload -->* no onload marco Javascript 7 06-24-2006 08:39 PM
Help. SessionID is x then y then x then y BodiKlamph@gmail.com ASP General 0 09-03-2005 03:02 PM
Why doesn't frameset onload event get called when each of the frames has an onload? adnanx82@gmail.com Javascript 5 05-15-2005 01:58 PM
base.OnLoad called, OnLoad not executed Fabio R. ASP .Net 0 03-25-2005 01:21 PM
window.onload and body.onload differences David Otton Javascript 2 11-04-2004 04:34 PM



Advertisments