send a request before close window

Posted on 2000-04-20
Last Modified: 2008-03-06
I need to send a string to the server for verify the user logout while the user close the "browser window" in NS4+ or IE4+ (when they click the cross, not the button in the webpage).

here is my code:


<script language=Javascript>
function logout() {

var temp = new String("/servlet/MServlet?FID=808&pageid=5&SID=");
temp = temp + "<%= sc.getSessionID() %>" + "&LANGID=" + "<%= sc.getLanguageID() %>" + "&SEQID=" + "<%= sc.getSequenceID() %>";

if (confirm("Are you sure to logout ?")) {
      document.location.href = temp;



<body onUnload="return logout(this)">



It works in IE4+ but not NS4+, I know it's hard to do it in NS4+. is there any way I can send the request logout string to the server when the user click the NS browser while close the window?
Any solution or answer I would appreciate.

thanks! :)

Question by:StoRmRiD3r
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 22

Expert Comment

ID: 2733884
Well, the main problem here is that you can't prevent the user from logging out. At least not in the onunload event. The program will always be shut down no matter what...IE has an exception there.
The best thing you could possible do is to have a seperate button which will handle this close event.
I don't know for what kind of page it is, if it is for the intranet this'd be the best solution. For the internet you might want to wait for another answer from (probably mplungjan) another expert here.

LVL 22

Expert Comment

ID: 2733892
Or when the user doesn't want to log out that you open a new window with the same URL???
LVL 75

Accepted Solution

Michel Plungjan earned 50 total points
ID: 2734384
It is not possible to detect the click on the cross unless you have your session open in a new window without location bar.

If so and assuming there are no links leading away from the page, try this:

Write a cookie with the userid and stuff.
Then use

<body onUnload="'<%= sc.getSessionID() %>&LANGID=<%= sc.getLanguageID() %>&SEQID=<%= sc.getSequenceID() %>','newwin')">

and return a script with a <body onLoad="self.close()">

It is a good idea to have the url fully qualified since older Netscape 4s forget where they came from...

If you have links on the page leading to other pages where you need to stay logged on, you need more tests

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

LVL 75

Expert Comment

by:Michel Plungjan
ID: 2734391
Sorry, forget the cookie if you send the complete url only if you do not want to have a long url write a cookie and use
<body onUnload="'','newwin')">

and have the servlet read the cookie


Author Comment

ID: 2735073
really thank you for your advices, CJ_S & Michel.

the body onUnload then is working on NS4+ & IE4+. thanks for your help.

CJ_S, I would give 20 pts for your comment. i will add a new question, the title is : "PTS for CJ_S".

thanks again, Expert. :)

Author Comment

ID: 2735079
Excellent! Expert. :)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question