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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if browser is still connected?

Status
Not open for further replies.

redgenie

Programmer
Aug 10, 2000
36
GB
Hi everyone,

I have a CGI script which performs a fair bit of work and I want to stop it running if the user closes their browser or hits back etc.

It's pretty easy in asp, as I could use Response.isClientConnected

Take a look at the following code:

Code:
print "Content-Type: text/html\n\n"; 

	while ($recordExists) { 

	# HERE I WOULD LIKE TO CHECK IF THE CLIENT IS CONNECTED OTHERWISE TERMINATE SCRIPT 

	my $recordData=getRecordData(); 
	print "Data: ${recordData}<br>"; 

	$recordExists=isThereAnother(); 
} 

print "Done!"; 

exit;

Is it possible? Any help would be greatly appreciated....

 
Not that I know of. I would image that the 'isClientConnected' code is maybe an ASP->Internet Explorer thing, there's nothing in the RFC to handle this.
 
I have actually found a way to do this but there is a downside. It only works with PerlScript so I think is only available to Win32 users unfortunately.


The code below works fine:

Code:
<% @LANGUAGE="PerlScript" %>
<%
	require 'loggingLibrary.pl';

	for(my $i=0;$i<100;$i++) {
		if ($Response->{IsClientConnected}) {
			# Do whatever
		} else {
			writeToLog("Script terminated at step: $i");
			exit;
		}
	}
%>

Depending on how fast the loop executes you may want to "mod" the isClientConnected test so it doesn't test on every pass.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top