사용자가 페이지를 새로 고치지 못하도록하고 싶습니다. 어떻게해야합니까? 나는 e.preventDefault
메서드를 사용하고 있지만 제대로 실행되지 않습니다.사용자가 페이지를 새로 고침하지 못하도록합니다.
답변
도 사용할 수 있습니다. 이전까지는로드하지 않았습니다.
window.onbeforeunload = function() {
return "you can not refresh the page";
}
Chrome에서 작동하지 않는 이유는 무엇인가요? –
window.onbeforeunload = function (event) { event.returnValue = "뭔가 영리한 글씨를 쓰십시오 .."; }; –
지원되지 않는 이유 : https://developers.google.com/web/updates/2016/04/chrome-51-deprecations?hl=ko#remove-custom-messages-in-onbeforeload-dialogs –
같은 시도 :이 기능에 대한
<script type="text/javascript">
// Callback
window.onbeforeunload = function(e) {
// Turning off the event
e.preventDefault();
}
</script>
몇 가지 기본 설명을
로 preventDefault : http://www.w3schools.com/jsref/event_preventdefault.asp
beforeunload : http://www.w3schools.com/jsref/event_onbeforeunload.asp
공유하시기 바랍니다 요 통해 작동합니다. –
사실, 그렇게 할 수는 없습니다. 당신이 할 수있다하더라도, 당신은해서는 안됩니다. –
'$ (someElement) .someAction (function (e) {});'또는 이벤트가 끝날 때'return false'를 사용하여 이벤트에 적절하게'e '를 보내야합니다. – GONG