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!

navigating from site & run script

Status
Not open for further replies.

jjob

Programmer
Jul 16, 2002
157
GB
I'm looking at a script that is supposed to 'logout' a user if the user 'closes' the browser or navigates away from the site.

The relevant code is show below (IP and site details edited to protect the innocent!!)

There is also an error handler shown in the second code block, which calls the close.asp. This is supposed to be called when the user has navigated to any sites where the an error is generated when attempting to access the host info.

Neither closing the current window nor navigating to another site calls script that closes the session. Has anyone any suggestions, I seem to get different results each time I run this.

TIA

JOB



The code below occurs in the <BODY> block.

Code:
onerror = handleError;

if( (opener.closed == true) ||((opener.top.location.host != 'my_first_site') && (opener.top.location.host != 'my_second_site') && (opener.top.location.host != '99.999.999.99') && (opener.top.location.host != '88.888.88.88'))  {

alert('opener moved No Error - Redirect to Close.asp')
top.location = 'Close.asp'
}

else {
  alert('Body No Error - Close Window')
  top.close()
}


code below is before the <HTML> tag


Code:
	if(opener.closed != true)
	{
		opener.focus;
	}
	
	function handleError()
	{
		top.location = 'Close.asp';
		return true;
	}
 
I can't see an obvious flaw. There's a couple of ; missing
Code:
alert('opener moved No Error - Redirect to Close.asp');
top.location = 'Close.asp';
}

else {
  alert('Body No Error - Close Window');
  top.close();
}

Don't know if they would actually cause a browser to error, but they might.

----------
I'm willing to trade custom scripts for... [see profile]
 
TVM Stormbind,

however the syntax errors were down to me editing out various server addresses and other sensitive info, these are safe in the scripts as this is not a but displaying them outside of the company would have led to my sacking!!

In fact since I've posted this, I've experimented with the scripts and realised what the problems were, there were 2 , one was my stupidity in that I've recently had a machine upgrade and reinstalled all software, BUT, forgot to disable the script debugging on my browser, which led to some odd results. Once I sorted that out, it became clear that the problem was a timing one, the "session checker" page was called and opened before the opener page had time to complete it's transitions, thus the scripts checking for the opener state always thought it was OK.

The problem was solved by

a)taking the checking script from the body of the session check page and putting it into a function called 'checkSession'.

b) creating a function called 'delay' which used the setTime (can't remember the exact name now!!) which takes a delay, and a function (in this case the checkSession function) that will be called after the timer expires.

c) calling the delay function in the onload event of the body.

Now all works perfectly, and the code is much neater and cleaner too!

But thanks for your time.

regards

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top