Solved

send a request before close window

Posted on 2000-04-20
6
1,721 Views
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:

<html>
<head><title>
</title>


<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;
}
}

</script>

</head>

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

asdffsadf

</body>
</html>

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! :)

rider
0
Comment
Question by:StoRmRiD3r
  • 2
  • 2
  • 2
6 Comments
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
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.

0
 
LVL 22

Expert Comment

by:CJ_S
Comment Utility
Or when the user doesn't want to log out that you open a new window with the same URL???
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 50 total points
Comment Utility
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="window.open('http://www.yourserver.com/servlet/MServlet?FID=808&pageid=5&SID=<%= 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

Michel
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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="window.open('http://www.yourserver.com/servlet/MServlet','newwin')">

and have the servlet read the cookie


Michel
0
 

Author Comment

by:StoRmRiD3r
Comment Utility
really thank you for your advices, CJ_S & Michel.

Michel,
the body onUnload then window.open 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. :)
0
 

Author Comment

by:StoRmRiD3r
Comment Utility
Excellent! Expert. :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now