473,385 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

but that doesn't work.

Can something of this sort be done?

Jul 23 '05 #1
2 7581
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 <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #2
On Wed, 20 Oct 2004 17:06:20 GMT, Grant Wagner
<gw*****@agricoreunited.com> 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).


Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: alanstew | last post by:
With the body tag calling out 'window onload', a function with a 'window.open' fails at the 'window.open' line. If I cut out the body tag, the function executes as normal. At first I thought it...
4
by: Eric Osman | last post by:
It seems as though when I use window.open I can't immediately do winId.document.getElementById("someDivTagInTheWindow") because window.open returns to my code before the html in the window is...
3
by: NeverLift | last post by:
But, if it's not open, I don't want to open it . . . using window.open will open it if it doesn't exist, even if the url in that open is null (the window is then empty -- but it's open). The...
2
by: Jenny | last post by:
In the code below, I can write html content var t='<body BGCOLOR=blue>' for a new window. But if it contains javascript, such as var t='<body onload="window.open('new1.html')">', this code will...
2
by: Beni Rose | last post by:
I'm trying to open a new window using window.open and then print that window once it's loaded. It works fine in Firefox, but not at all in IE. No matter what I put in my onload, it gets ignored....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.