jQuery 를 이용해서 죠런 기능을 구현할려면 요렇게 하면 된다.
<script>
var checkUnload = true;
$(window).on("beforeunload", function(){
if(checkUnload) return "이 페이지를 벗어나면 작성된 내용은 저장되지 않습니다.";
});
</script>
단, 글쓰기 버튼을 클릭해서 글을 저장한 후 페이지를 이동할때도 저런 메시지가 뜨기 때문에, 고럴땐 checkUnload 값을 false 로 바꿔준 후 submit 이나 페이지를 이동해야 한다~
$("#saveBtn").on("click", function(){
checkUnload = false;
$("#saveForm").submit();
});
출처 : http://stove99.tistory.com/128
'Publishing' 카테고리의 다른 글
[javascript]stopPropagation() 과 preventDefault() 차이점 (0) | 2015.05.29 |
---|---|
[javascript]브라우져 종료 이벤트 (0) | 2015.05.28 |
carouFredSel (0) | 2015.04.27 |
[javascript]regexp (0) | 2014.09.12 |