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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…