Solution to closing IE window and clearing Session_javascript skills
//function window.onunload() { alert(' This is what you have to do, close the web page! '); location = 'SessionClear.aspx'; }
//function window.onbeforeunload() { alert('This is what you have to do, close The page was made before! ') }
function window.onunload() {
" // Actions that need to be triggered when the user closes abnormally Location = 'Handler1.ashx';
}
}
Handler1.ashx:
using System.Web;
using System.Web.Services;
using System.Web.SessionState;
namespace WebApplication1
{ ///
/// Summary description of $codebehindclassname$
///
[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
{
{
return false;
}
}
}
}
Explanation :
Fortunately, I finally found a method on the Internet that can capture events when the user uses Alt F4, right-clicks the title bar to close, double-clicks the title bar, or directly presses the close button. Of course, minimizing to the taskbar and then closing it cannot be captured.
Instructions:
window.screenLeft = 10000 border width (2×2) = 10004
window.screenTop = 10000 toolbar height title bar height = 10097
It should be noted that in onBeforeUnload, these coordinate attributes of the screen are normal values.
screenLeft: Gets the x-coordinate of the upper left corner of the browser client area relative to the upper left corner of the screen.
screenTop: Gets the y coordinate of the upper left corner of the browser client area relative to the upper left corner of the screen.
I guess that a special value will be generated when the form is destroyed. In a click test under normal circumstances, the value will not exceed this value.
The problem now is that using window.location in onBeforeUnload can submit the request to the specified URL normally, but this method cannot be effectively executed in the onUnload event. The solution is to open a new window and close it.
We can write something like this to replace the series of window.locations used in the past. Because the portal involves multiple cross-server website servers. After exiting from the unified entrance, you need to exit sequentially in order to achieve the desired effect of the portal website.
var newWindow;
window.opener=null;
newWindow=window.open(URL,PageName, 'height=0,width=0');
newWindow.opener=null;
newWindow.close();
……
This code has been tested. Do not use window.close in onUnload because the event will be triggered immediately before the object is destroyed. And onBeforeUnload is an event triggered before the page is unloaded.
The so-called clearing is essentially to call the page with the exit function directly by opening a new window. There may be a pause for a second or two when the call is made to close, or the window may be closed on a dedicated exit page. The difference between this page and normal exit and switching back to the homepage is that it will be automatically closed after exiting and can be opened directly without additional control.
[Note] If no judgment is made in window.onUnload, this event will be triggered when the current page changes, such as refreshing the page. Therefore, judgment must be made to capture specific operations in order to block some normal operations.
Continued: How to clear the Session before the user directly closes the window in IE
I explained the implementation idea yesterday, but in actual operation I found that a delay must be added to ensure that the program can be executed normally. The implementation details are attached below, along with a simple time delay function. The code has been tested.
Second, when the window loads or exits, if you want to refresh the browser once, you can do the following:
Refresh on close

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The problem was found in the springboot project production session-out timeout. The problem is described below: In the test environment, the session-out was configured by changing the application.yaml. After setting different times to verify that the session-out configuration took effect, the expiration time was directly set to 8 hours for release. Arrived in production environment. However, I received feedback from customers at noon that the project expiration time was set to be short. If no operation is performed for half an hour, the session will expire and require repeated logins. Solve the problem of handling the development environment: the springboot project has built-in Tomcat, so the session-out configured in application.yaml in the project is effective. Production environment: Production environment release is

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Solution to the problem that the php session disappears after refreshing: 1. Open the session through "session_start();"; 2. Write all public configurations in a php file; 3. The variable name cannot be the same as the array subscript; 4. In Just check the storage path of the session data in phpinfo and check whether the sessio in the file directory is saved successfully.

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

The default expiration time of session PHP is 1440 seconds, which is 24 minutes, which means that if the client does not refresh for more than 24 minutes, the current session will expire; if the user closes the browser, the session will end and the Session will no longer exist.

Problem: Today, we encountered a setting timeout problem in our project, and changes to SpringBoot2’s application.properties never took effect. Solution: The server.* properties are used to control the embedded container used by SpringBoot. SpringBoot will create an instance of the servlet container using one of the ServletWebServerFactory instances. These classes use server.* properties to configure the controlled servlet container (tomcat, jetty, etc.). When the application is deployed as a war file to a Tomcat instance, the server.* properties do not apply. They do not apply,

1. Implementing SMS login based on session 1.1 SMS login flow chart 1.2 Implementing sending SMS verification code Front-end request description: Description of request method POST request path /user/code request parameter phone (phone number) return value No back-end interface implementation: @Slf4j@ ServicepublicclassUserServiceImplextendsServiceImplimplementsIUserService{@OverridepublicResultsendCode(Stringphone,HttpSessionsession){//1. Verify mobile phone number if

It's no secret that Internet Explorer has fallen out of favor for a long time, but with the arrival of Windows 11, reality sets in. Rather than sometimes replacing IE in the future, Edge is now the default browser in Microsoft's latest operating system. For now, you can still enable Internet Explorer in Windows 11. However, IE11 (the latest version) already has an official retirement date, which is June 15, 2022, and the clock is ticking. With this in mind, you may have noticed that Internet Explorer sometimes opens Edge, and you may not like it. So why is this happening? exist
