How to close the ie window and clear the Session _ javascript skills

Source: Internet
Author: User
This article mainly introduces how to close the ie window to clear the Session. If you need a friend, please refer to it and hope to help you. The Code is as follows:


// Function window. onunload () {alert ('This is what you want to do. It is done after you close the webpage! '); Location = 'sessionclear. aspx ';}
// Function window. onbeforeunload () {alert ('This is what you have to do. It was done before closing the webpage! ')}

Function window. onunload (){

If (window. screenLeft> = 10000 & window. screenTop> = 10000) | event. altKey ){
Alert (window. screenLeft + "," + window. screenTop );
// The Action to be triggered when the user shuts down abnormally
Location = 'handler1. ashx ';
}
}

Script


Handler1.ashx:

The Code is as follows:


Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. Services;
Using System. Web. SessionState;

Namespace WebApplication1
{
///


/// $ Codebehindclassname $ abstract description
///
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
Public class Handler1: IHttpHandler, IRequiresSessionState
{

Public void ProcessRequest (HttpContext context)
{
Context. Response. ContentType = "text/plain ";
Context. Session. Abandon ();
Context. Session. Clear ();
}

Public bool IsReusable
{
Get
{
Return false;
}
}
}
}


Explanation:

Generally, a website in the form of a member creates a session or Cookie after the member logs in. Then, the member needs to exit the connection or click the button to exit when the member exits. When a member closes the form directly, a series of exits related to exit are not triggered. These will not be cleared until the server session expires.

Fortunately, on the network, we finally found a way to capture events that users can use Alt + F4, right-click the title bar, double-click the title bar, and directly press the close button. Of course, it cannot be captured to minimize to the taskbar and then close it.

The Code is as follows:


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.