jQuery/Load, Unload Event
jQuery Load,Unload Event Handling
Soul-Learner
2014. 7. 10. 12:58
$(document).ready(), $(window).on('beforeunload', function)
$(document).ready()
- 웹브라우저의 메모리에 HTML 코드가 로드되고 DOM 오브젝트가 생성되면 호출됨
$(window).unload()
- 웹브라우저의 메모리에 로드된 HTML문서가 제거되고 다른 HTML문서로 변경될 때
- Google Chrome에서는 $(window).on('beforeunload', function) 으로 가능함
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>jQuery Test</title>
<script type="text/javascript" src="jquery-2.1.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
/*
$(window).unload(function(){
alert('이용자 떠남');
console.log('이용자 떠남');
});*/
// Chrome에서는 다음과 같은 방법으로 unload 이벤트를 대신할 수 있다
$(window).on('beforeunload', function(){
console.log("이용자 떠남!");
});
});
</script>
</head>
<body>
</body>
</html>