0

Ok so I have a site that I want to automatically close the window when the focus is lost from the page. For example, if the user clicks off the page to something else on there desktop I want the page to close. So far I have managed to do this but the grids on my page and the scroll bars all trigger the close function when clicked on. Is there anyway to make the scroll bars and drop down boxes not trigger the function?

This is the code I have so far.

<body onfocusout="javascript:window.opener='x';window.close();">

Thanks!

2
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by rakhi4110
0

Hi JOUATT,

Well i used this and i was able to close my parent window. May be try this and see if it works.

<script language="text/javascript">
function closeParent()
{
var s=window.opener;
s.close();
}
</script>

Since you were using window.close() i think it will close your child window, though i'm not sure about that.
See if the above can be of any help to you.

Thanks and regards,
RAKHI

0

I came up with an error on the function "undefined is null or not an object". The error was triggered when I click on a scroll bar so im thinking that that function would do the same thing that my function would do. Should have mentioned before that I am testing in IE.

0

Though am not exactly sure about your problem, i think i can give a solution if i take a look at the code snippet of your script..

0

here is a snippet of my code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Alert Window</title>
<script type="text/javascript">
function closeParent()
   
      {
   
      var s=window.opener;
   
      s.close();
   
      }
   
      

    </script>
</head>
<body onfocusout="closeParent();">
<!--<body onfocusout="javascript:window.opener='x';window.close();">-->

blah blah..The rest of my page

Edited by JOUATT: n/a

0

I still haven't gotten this to work right. Any help would be appreciative. Thanks.

0

Well JOUATT,

Sry for replying late..
You can use the onBlur event for this.

I'll show a really simple example which worked on IE7,8 and IE9 too..
You can use it if u want in your code and check whether it is working or not..
And kindly inform me if it does...

The code for the parent window..

<html><head>
<script language="javaScript">
function new_child()
{
window.open("x.html","child",toolbar=0,status=0,menubar=0);
}
</script>
</head>
<body>
<form name="f1">
<input type="button" name="b1" onclick="new_child()"/>
</form>
</body>
</html>

And this is the code for the child window x.html

<html>
<head>
<script language="javaScript">
function closeWindow()
{
opener.window.close();
}
</script>
</head>
<body onBlur="closeWindow()">
Hai
</body>
</html>

Inform me in any case. If you want to know how to avoid the confirmation box before the parent window closes,Kindly visit this link
Thanks and regards,
RAKHI

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.