PDA

View Full Version : Detect Browser Windows...


Horus_Kol
11-14-2005, 10:28 AM
the background
I came up with javascript which could detect whether a user was leaving my intranet and automatically log them out...


<script type='text/javascript'>
<!--
function logout_Check()
{
if (this.opener.closed)
{
// window is closed
query = this.location.search;
uid = query.substr(5)

this.location = "logout.php?uid=" + uid + "&logout=&closed=";
}
else
{
try
{
if (this.opener.location != "")
{
url_opener = this.opener.location;
}
}
catch(e)
{
url_opener = "outside";
}

if (url_opener == "outside")
{
// page is outside of the intranet
query = this.location.search;
uid = query.substr(5)

this.location = "logout.php?uid=" + uid + "&logout=&navigate=";
}
else
{
this.close();
}
}
}

// -->
</script>

This is run in a seperate pop window when a page onunload event occurs in the main browser window...

it can detect when the user is closing the window, or when he has navigated away from the intranet...

the problem is, it doesn't work if they have multiple windows open - so if they want a different document open in two windows, and then close one of them, he will be logged out of the intranet and his next navigation in the remaining window will require a log in again...

so... the question: does anyone know how to detect any open browser window and test its location property?

cheers,

HK