46
rated 0 times
[
47]
[
1]
/ answers: 1 / hits: 71630
/ 15 Years ago, thu, september 3, 2009, 12:00:00
Is there an easy hook for detecting that a window opened by a script has finished loading? Basically, I want the equivalent of the onLoad()
hook, but I can't set it directly -- assume that the child document is a given and I can't actually put any code of my own in it.
For instance, say I have the following two files:
parent.html
:
<html>
<head>
<title>Parent</title>
</head>
<script type=text/javascript>
var w;
function loadChild() {
w = window.open();
w.location.href=child.html;
// block until child has finished loading... how?
w.doSomething();
}
</script>
</html>
<body>
I am a parent window. <a href=javascript:loadChild()>Click me</a>.
</body>
child.html
:
<html>
<head>
<title>Child</title>
</head>
<script type=text/javascript>
function doSomething() {
alert(Hi there);
}
</script>
</html>
<body>
I am a child window
</body>
Since setting location.href is non-blocking, w.doSomething()
isn't defined yet and the doSomething()
call blows up. How can I detect that the child has finished loading?
More From » javascript