Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onBlur close() w/o body onblur=window.close()

Status
Not open for further replies.

DeZiner

Programmer
May 17, 2001
815
US
How does one close the popup window when it loses focus?

If I use <body onBlur=window.close()> the window opens then closes immediately throwing an error saying the callee was cancelled and the script did not run.

DeZiner
gear.gif width=45 align=left
When the gears stop turning,
we all stop learning.
 
Hi DeZiner,

This is just an idea, but maybe you can try the following:

add a variable: loaded = false;

Then use the following in your body tag:

Code:
<body onload=&quot;loaded=true&quot; onBlur=&quot;if (loaded) { window.close() }&quot;>

Sure hope it works :p

Gtz,

Kristof
 
hie
DeZigner, here is how i did it:
var fClose=0

function doClose(){
if(fClose)close();
}

function _blur(){
fClose=1;
setTimeout(&quot;doClose()&quot;,100);
}
</script>


<body onblur=&quot;_blur()&quot;> Victor
 
Vituz,

Thanks...it works the first time however, the 2nd time the window is opened it closes immediately, any idea how to keep it open until it blurs again?

I know I don't have to keep closing it but just want to. Thanks in advance. DeZiner
gear.gif width=45 align=left
When the gears stop turning,
we all stop learning.
 
Any other ideas? DeZiner
gear.gif width=45 align=left
When the gears stop turning,
we all stop learning.
 
ok, DeZiner, try this:
~~~~~~~~
<html>
<head>
<title>pappa</title>
<script>
function op(url){
var wnd
wnd=window.open(url,'','')
}
</script>
</head>
<body bgcolor=&quot;#FFFFFF&quot;>
<a href=&quot;javascript:void(op('closin_onblur.htm'))&quot;>open self closing window</a>
</body>
</html>

~~~~~~~~
<html>
<head>
<title>closin onblur</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<script>
var fClose=0

function doClose(){
if(fClose)close();
}

function _blur(){
fClose=1;
setTimeout(&quot;doClose()&quot;,100);
}

onload=function(){
fClose=0
onblur=_blur
}
</script>
</head>

<body >
</body>
</html>
Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top