Behavior is inconsistent across browsers. In Firefox I can get it to work onload of the opened page from the opener page by setting the opened page's onload event from the opener. In IE I have to set the onload event on the opened page. That works in Firefox too, but seems less elegant than having all of the custom code on the opener. Also in IE this should be done live due to IE's restrictions on local javascript in newly opened windows.
Both browsers allowed me to run functions on the opened page from the opener page once the opened page had fully loaded.
From previous experience I'm assuming that jQuery must be on the opened page. This assumption might be false. I'll test that later.
So I came up with (note that I've put everything in the same folder for simplicity's sake) -
index.htm:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
var popupWin2;
function doit(){
if(!popupWin2.document || !popupWin2.document.getElementById || !popupWin2.document.getElementById('cont') || !popupWin2.$){
setTimeout(doit, 500);
return;
}
popupWin2.$('#cont').load('content1.htm');
}
function loadPopUp2(url2){
if(popupWin2 && popupWin2.open){
popupWin2.close();
}
popupWin2 = open(url2, "myWin", "width=500, height=400");
doit();
popupWin2.moveTo(600, 0);
}
</script>
</head>
<body>
<a href="popup2.htm" onclick="loadPopUp2(this.href); return false;">create & load</a><br>
<a href="#" onclick="try{popupWin2.$('#cont').load('content2.htm'); popupWin2.focus();}catch(e){} return false;">load</a>
</body>
</html>
popup2.htm:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
</head>
<body>
popup2.htm
<div id="cont"></div>
</body>
</html>
content1.htm:
Code:
<div>
content1.htm
</div>
content2.htm:
Code:
<div>
content2.htm
</div>
Edit: Added Later:
We can put all the script code on the index page if we do it like so:
index.htm (new):
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
var popupWin2;
function doit(){
var c;
if(!popupWin2.document || !popupWin2.document.getElementById || !(c = popupWin2.document.getElementById('cont'))){
setTimeout(doit, 500);
return;
}
$(c).load('content1.htm');
}
function loadPopUp2(url2){
if(popupWin2 && popupWin2.open){
popupWin2.close();
}
popupWin2 = open(url2, "myWin", "width=500, height=400");
doit();
popupWin2.moveTo(600, 0);
}
</script>
</head>
<body>
<a href="popup2.htm" onclick="loadPopUp2(this.href); return false;">create & load</a><br>
<a href="#" onclick="try{var c = popupWin2.document.getElementById('cont'); $(c).load('content2.htm'); popupWin2.focus();}catch(e){} return false;">load</a>
</body>
</html>
popup2.htm (new):
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
popup2.htm
<div id="cont"></div>
</body>
</html>
Bookmarks