2014-05-19 1 views
1

마지막 날에 웹 사이트 페이지를 떠나기 전에 확인해야하는 확인 알림이 Chrome 및 Firefox에는 표시되지 않지만 IE에는 표시됩니다. Google Chrome 개발자 도구를 사용하여 디버깅하는 경우 확인 기능이 실행되고 if 문을 입력하지만 알림 상자가 표시되지 않는 것을 볼 수 있습니다. Chrome을 다시 시작하고 알림 메시지를 재설정하는 옵션을 찾으려고했지만 아무 것도 찾지 못했습니다. 아이디어가 있으십니까? 크롬과 Firefox에서 onbeforeunload 문제가 발생했습니다.

코드

은 이것이다 : 나는 작업 솔루션을 찾았

if (window.addEventListener) { 
        window.addEventListener('beforeunload', confirm, false); 
       } 
       else window.attachEvent("onbeforeunload", confirm); 

... 

function confirm(e) { 
    if (changed== true) { 
     return "You haven't saved your changes!"; 
    } 
} 

답변

1

하지만,는 attachEvent 더 이상 작동하지 않는 이유를 실제로 이해하지 않습니다.

내가에서 addEventListener와는 attachEvent 라인 제거 : 어쨌든,이 IE, 크롬과 파이어 폭스에서 테스트 작업 솔루션 인 HTML에서

/* if (window.addEventListener) { 
        window.addEventListener('beforeunload', confirm, false); 
       } 
       else window.attachEvent("onbeforeunload", confirm); */ 

, 나는이 속성은 body 태그에 onbeforeunload 추가

function confirmEvent(e) { 
    if (changed== true) { 
     return "You haven't saved your changes!"; 
    } 
} 
:
<body onbeforeunload="return confirmEvent()"> 

는 또한 내장 된 자바 스크립트 함수 확인과 혼동을 피하기 위해입니다 onbeforeunload 기능을 이름

+0

브라우저가 OS 종료로 인해이 작업 닫는 경우 알아? –

1

window.addEventListener("beforeunload", function (e) { 
    var confirmationMessage = "\o/"; 

    e.returnValue = confirmationMessage;  // Gecko and Trident 
    return confirmationMessage;    // Gecko and WebKit 
}); 

https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload 내가 테스트 모든 브라우저에서 근무 참조)

PS를 : 나는 그것 늦게 조금