champ_010
asked on
onUnload Close PopUp Window!
I have a standard popup window and a frameless sliding window that appears onLoad of my webpage.
The frameless sliding window has an autoclose onUnload of the parent window, but the standard popup does not.
How do I ad this to my <body> tag of the parent window?
This is what I have so far, but not working:
<body onload="openFrameless(); popWindow('window.htm',nam e,'190','1 20','no'); return false;" onUnload="popWindow.close( )">
Thanks.
The frameless sliding window has an autoclose onUnload of the parent window, but the standard popup does not.
How do I ad this to my <body> tag of the parent window?
This is what I have so far, but not working:
<body onload="openFrameless(); popWindow('window.htm',nam
Thanks.
You need to create a "handle" for your pop up window, so you can reference (and close it) later... try doing something like this..
<html>
<head>
<title>Untitled</title>
</head>
<script>
var pop='';
function openPop()
{
pop = window.open('window.htm',' ','width=1 90,height= 120');
}
function closePop()
{
pop.close();
}
</script>
<body onload="openPop();" onUnload="closePop();">
</body>
</html>
<html>
<head>
<title>Untitled</title>
</head>
<script>
var pop='';
function openPop()
{
pop = window.open('window.htm','
}
function closePop()
{
pop.close();
}
</script>
<body onload="openPop();" onUnload="closePop();">
</body>
</html>
ASKER
Rodnex,
I am using a script I found on the internet. How do I integrate your example to this?:
<script type=text/javascript>
var win= null;
function popWindow(win,name,w,h,scr
var winl = (screen.width-w)/2;
var wint = 5
var settings ='height='+h+',';
settings +='width='+w+',';
settings +='top='+wint+',';
settings +='left='+winl+',';
settings +='scrollbars='+scroll+','
settings +='resizable=no';
win=window.open(win,name,s
if(parseInt(navigator.appV
}
</script>
<body onload="openFrameless(); popWindow('window.htm',nam
for your <body> tag, change to this:
<body onload="openFrameless(); popWindow('window.htm',nam e,'190','1 20','no'); return false;" onUnload="win.close();">
<body onload="openFrameless(); popWindow('window.htm',nam
This would probably do it. It will try to close the pop up on window unload.
Why not include the entire page here so I can see the other functions...
<html>
<head>
<script type=text/javascript>
var win = null;
function popWindow(w)
{
win = window.open(w,'','height=1 20,width=1 90,top=5,, left=5,scr ollbars=no ,resizable =no');
if(parseInt(navigator.appV ersion) >= 4){win.window.focus();}
}
function closePop()
{
if (typeof(win)!="undefined") {
win.close();
}
}
</script>
</head>
<body onload="openFrameless(); popWindow('window.htm');" onUnload="closePop();">
</body>
</html>
Why not include the entire page here so I can see the other functions...
<html>
<head>
<script type=text/javascript>
var win = null;
function popWindow(w)
{
win = window.open(w,'','height=1
if(parseInt(navigator.appV
}
function closePop()
{
if (typeof(win)!="undefined")
win.close();
}
}
</script>
</head>
<body onload="openFrameless(); popWindow('window.htm');" onUnload="closePop();">
</body>
</html>
ASKER
Your code opens the window, but it still doesn't close when I go to another page.
Here is what I have on the page with your code and the frameless window script I got from CodeLifter.com:
<html>
<head>
<title>None</title>
<script>
var win = null;
function popWindow(w)
{
win = window.open(w,'','height=1 20,width=1 90,top=5,, left=5,scr ollbars=no ,resizable =no');
if(parseInt(navigator.appV ersion) >= 4){win.window.focus();}
}
function closePop()
{
if (typeof(win)!="undefined") {
win.close();
}
}
</script>
<script>
var windowW=180
var windowH=280
var Yoffset=0 // in pixels, negative values allowed
var windowStep=2 // move increment (pixels)
var moveSpeed=10 // move speed (larger is slower)
Xmode="right";
Xoffset=18;
var urlPop = "http://www.yahoo.com"
var title = "no title";
var autoclose = true
var windowX = (screen.width/2)-(windowW/ 2);
if (Xmode=="left") windowX=0+Xoffset;
if (Xmode=="right") windowX=screen.availWidth- Xoffset-wi ndowW;
var windowY = (screen.availHeight);
var windowYstop = windowY-windowH-Yoffset;
var windowYnow = windowY;
s = "width="+windowW+",height= "+windowH;
var beIE = document.all?true:false
function openAd(){
if (beIE){
PFW = window.open("","popFramele ss","fulls creen,"+s)
PFW.blur()
window.focus()
PFW.resizeTo(windowW,windo wH)
PFW.moveTo(windowX,windowY )
var frameString=""+
"<html>"+
"<head>"+
"<title>"+title+"</title>" +
"</head>"+
"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
"<frame name='top' src='"+urlPop+"' scrolling=auto>"+
"<frame name='bottom' src='about:blank' scrolling='no'>"+
"</frameset>"+
"</html>"
PFW.document.open();
PFW.document.write(frameSt ring)
PFW.document.close()
} else {
PFW=window.open(urlPop,"po pFrameless ","scrollb ars,"+s)
PFW.blur()
window.focus()
PFW.resizeTo(windowW,windo wH)
PFW.moveTo(windowX,windowY )
}
PFW.focus()
if (autoclose){
window.onunload = function(){PFW.close()}
}
movePFW();
}
function movePFW(){
if (document.all){
if (windowYnow>=windowYstop){
PFW.moveTo(windowX,windowY now);
PFW.focus();
windowYnow=windowYnow-wind owStep;
timer=setTimeout("movePFW( )",moveSpe ed);
}else{
clearTimeout(timer);
PFW.moveTo(windowX,windowY stop);
PFW.focus();
}
}else{
PFW.moveTo(windowX,windowY stop);
}
}
</script>
</head>
<body onload="openAd(); popWindow('window.htm');" onUnload="closePop();">
</body>
</html>
Here is what I have on the page with your code and the frameless window script I got from CodeLifter.com:
<html>
<head>
<title>None</title>
<script>
var win = null;
function popWindow(w)
{
win = window.open(w,'','height=1
if(parseInt(navigator.appV
}
function closePop()
{
if (typeof(win)!="undefined")
win.close();
}
}
</script>
<script>
var windowW=180
var windowH=280
var Yoffset=0 // in pixels, negative values allowed
var windowStep=2 // move increment (pixels)
var moveSpeed=10 // move speed (larger is slower)
Xmode="right";
Xoffset=18;
var urlPop = "http://www.yahoo.com"
var title = "no title";
var autoclose = true
var windowX = (screen.width/2)-(windowW/
if (Xmode=="left") windowX=0+Xoffset;
if (Xmode=="right") windowX=screen.availWidth-
var windowY = (screen.availHeight);
var windowYstop = windowY-windowH-Yoffset;
var windowYnow = windowY;
s = "width="+windowW+",height=
var beIE = document.all?true:false
function openAd(){
if (beIE){
PFW = window.open("","popFramele
PFW.blur()
window.focus()
PFW.resizeTo(windowW,windo
PFW.moveTo(windowX,windowY
var frameString=""+
"<html>"+
"<head>"+
"<title>"+title+"</title>"
"</head>"+
"<frameset rows='*,0' framespacing=0 border=0 frameborder=0>"+
"<frame name='top' src='"+urlPop+"' scrolling=auto>"+
"<frame name='bottom' src='about:blank' scrolling='no'>"+
"</frameset>"+
"</html>"
PFW.document.open();
PFW.document.write(frameSt
PFW.document.close()
} else {
PFW=window.open(urlPop,"po
PFW.blur()
window.focus()
PFW.resizeTo(windowW,windo
PFW.moveTo(windowX,windowY
}
PFW.focus()
if (autoclose){
window.onunload = function(){PFW.close()}
}
movePFW();
}
function movePFW(){
if (document.all){
if (windowYnow>=windowYstop){
PFW.moveTo(windowX,windowY
PFW.focus();
windowYnow=windowYnow-wind
timer=setTimeout("movePFW(
}else{
clearTimeout(timer);
PFW.moveTo(windowX,windowY
PFW.focus();
}
}else{
PFW.moveTo(windowX,windowY
}
}
</script>
</head>
<body onload="openAd(); popWindow('window.htm');" onUnload="closePop();">
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i just moved the closePop() function from <body> tag to the "window.onunload = function(){PFW.close(); closePop();}" line
oh and I forgot to close the body tag... heee...
oh and I forgot to close the body tag... heee...
try this,
function closePop(){
if(win && !win.close){
win.close();
}
}
then do the same
<body onload="openFrameless(); popWindow('window.htm');" onUnload="closePop();">
function closePop(){
if(win && !win.close){
win.close();
}
}
then do the same
<body onload="openFrameless(); popWindow('window.htm');" onUnload="closePop();">
ASKER
Works great Van-Kel. Thanks!
ASKER
It is works sometimes, but other times I am getting a javascript error:
Object expected "w" is undefined
I think it has to do with these two lines:
function popWindow(w)
{
win = window.open(w,'','height=1
What is the "w"?
ASKER
Van-Kel can you respond re: your code please.
strange... "w" is just a parameter of the function popWindow, and u only call popWindow once in ur page (right?), which is in your <body onload=...> tag... and in this case, "w" will be set to "window.html".... so "w" should be defined... unless u have altered the code and called the function popWindow without any parameters..
i didn't encounter the error u are mentioning...
i didn't encounter the error u are mentioning...
ASKER
No worries, the error line is where the <body onload=> tag, so it may be one of the other functions I have loading.
Thanks again.
Thanks again.
http://developer.irt.org/script/98.htm