window.onbeforeunload 및 window.onunload가 Firefox, Safari, Opera에서 작동하지 않습니까?
채팅 응용 프로그램에서 응용 프로그램이 종료되면 사용자로부터 확인을 받아야합니다.
그래서 window.onbeforeunload
확인 경고와 window.onunload
logout ()에 사용했습니다.
그러나 두 기능 모두 IE와 Chrome에서 작동합니다. (응용 프로그램은 정상적으로 작동합니다)
window.onbeforeunload
Opera에서 작동하지 않고 내 메시지가 Firefox에 표시되지 않습니다.window.onunload
Safari, Opera 및 Firefox에서 작동하지 않습니다.
내 자바 스크립트 코드는,
// Used for confirmation , to closing the window
window.onbeforeunload = function () {
return "Are you sure want to LOGOUT the session ?";
};
// Used to logout the session , when browser window was closed
window.onunload = function () {
if((sessionId != null)&&(sessionId!="null")&& (sessionId != ""))
logout();
};
또한 JQuery로 동일한 기능을 시도했습니다.
<script type="text/javascript">
$(window).on('beforeunload', function() {
return 'Are you sure want to LOGOUT the session ?';
});
$(window).unload(function() {
if ((sessionId != null) && (sessionId != "null") && (sessionId != "")) {
logout();
}
});
</script>
안타깝게도 사용중인 방법은 해당 브라우저에서 지원되지 않습니다. 내 대답을 뒷받침하기 위해 (이 비지 지적인 행동) 아래 링크를 제공했습니다.
onbeforeunload
그리고 이것을 지원하기 위해 ...에서 onunload
일하지 않습니다.opera
Opera의 onbeforeunload
http://www.zachleat.com/web/dont-let-the-door-hit-you-onunload-and-onbeforeunload/
하지만 onunload
이벤트가 완전하게 작동하지 않습니다, 당신이 사용할 수있는 onunload
사용자가 저장되지 않은 양식 페이지에서 다른 페이지로 이동하는 링크를 클릭하면 경고를 표시 할 수 있습니다.
onunload
safari
...에서 작동하지 않습니다.
https://www.webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/
pagehide
대신 사파리 브라우저에서 이벤트를 사용해 볼 수 onunload
있습니다.
onunload
firefox
...에서 작동하지 않습니다.
그들은 아직 FF에서도 해결책을 찾지 못했습니다.
행운을 빕니다.
즉, firefox 및 chrome에 대한 작업 솔루션은 다음과 같습니다.
var myEvent = window.attachEvent || window.addEventListener;
var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compitable
myEvent(chkevent, function(e) { // For >=IE7, Chrome, Firefox
var confirmationMessage = 'Are you sure to leave the page?'; // a space
(e || window.event).returnValue = confirmationMessage;
return confirmationMessage;
});
나는 jQuery와 함께 IE와 FF에서 작동하도록 할 수 있었다.
$(window).bind('beforeunload', function(){
});
대신 : unload, onunload 또는 onbeforeunload
I got the solution for onunload
in all browsers except Opera by changing the Ajax asynchronous request into synchronous request.
xmlhttp.open("POST","LogoutAction",false);
It works well for all browsers except Opera.
The onunload event is not called in all browsers. Worse, you cannot check the return value of onbeforeunload event. That prevents us from actually preforming a logout function.
However, you can hack around this.
Call logout first thing in the onbeforeunload event. then prompt the user. If the user cancels their logout, automatically login them back in, by using the onfocus event. Kinda backwards, but I think it should work.
'use strict';
var reconnect = false;
window.onfocus = function () {
if (reconnect) {
reconnect = false;
alert("Perform an auto-login here!");
}
};
window.onbeforeunload = function () {
//logout();
var msg = "Are you sure you want to leave?";
reconnect = true;
return msg;
};
Firefox simply does not show custom onbeforeunload messages. Mozilla say they are protecing end users from malicious sites that might show misleading text.
'Program Tip' 카테고리의 다른 글
Visual Studio에서 선택한 줄의 들여 쓰기를 수정하는 방법 (0) | 2020.10.23 |
---|---|
node.js의 process.on ( 'SIGINT')에 해당하는 Windows는 무엇입니까? (0) | 2020.10.23 |
상위 폴더가없는 경우 파일을 작성하는 방법은 무엇입니까? (0) | 2020.10.23 |
HTTP 및 HTTPS 요청 모두에 대해 서블릿에서 전체 URL 및 쿼리 문자열 가져 오기 (0) | 2020.10.23 |
Intellij Idea를 사용하여 Java 프로젝트에서 Jenkinsfile 구문 강조 (0) | 2020.10.23 |