ホームページ >ウェブフロントエンド >jsチュートリアル >IEウィンドウを閉じてSession_javascriptスキルをクリアするための解決策
関数 window.onunload() {
" // ユーザーが異常終了したときにトリガーする必要があるアクション Location = 'Handler1.ashx';
}
}
Handler1.ashx:
/// $codebehindclassname$ の概要説明
///
context.Session.Abandon();
session.Clear() ;
}
public bool IsReusable
{
{
return false;
}
}
}
}
説明:
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.