JavaScript - window.onload
JavaScriptWhat is window.onload?
1. A function excutes after All contents are loaded.
2. the only one window.onload exists in a document
3. it is possible using onload to body tag. for this case, window.onload is ignored.
priority ( body tag onload > window.onload )
<!--
window.onload = function(){}
1. html 문서에 포함된 모든 콘텐츠가 로드된 후에 실행하는 함수
2. 동일한 문서에 window.onload 는 단 하나만 존재해야한다.
3. body 태그에도 onload 속성을 지정할 수 있는데 이때 window.onload 속성은 무시된다.
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
window.onload = function(){ alert("First window.onload"); };
window.onload = function(){ alert("Second window.onload"); };
/* If using onloads method, last onload will excute (Overriding) */
/* jquery*/
$(document).ready(function() {
alert("First ready..");
});
$(document).ready(function() {
alert("Second ready..");
});
</script>
</head>
<!-- <body onload = "loading()"> -->
<body>
<h2>
hi~
</h2>
</body>
</html>
'JavaScript' 카테고리의 다른 글
JavaScript - Global Variable (0) | 2019.09.14 |
---|---|
JavaScript - Hoisting (0) | 2019.09.14 |
JavaScript - Escape character, Operator (0) | 2019.09.14 |
JavaScript - Datatype (0) | 2019.09.14 |
What is JavaScript? (0) | 2019.09.14 |