IT/JavaScript
자바스크립트 - onload를 사용해서 페이지 로딩시 특정 함수 호출
storya
2016. 3. 24. 19:28
이벤트 : load
이벤트 핸들러 : onload
페이지가 로드될 때 특정 함수를 호출시 사용
1. body 태그에 onload 명시
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>onload</title>
<script type="text/javascript">
function msg(){
var str = "Hello World!!";
alert(str);
}
</script>
</head>
<body onload="msg();">
</body>
</html>
2. window.onload 사용
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>onload</title>
<script type="text/javascript">
function msg(){
var str = "Hello World!!";
alert(str);
}
window.onload=msg;
</script>
</head>
<body>
</body>
</html>
반응형