K-DigitalTraining 강의/6. Javascript(웹표준)
[8주차] 33. location 객체의 새로고침, 사이트이동 [ reload(), href 속성 ]
이대곤
2022. 7. 9. 17:11
동일코드
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
now = new Date;
document.write(now.toString() + "<br>");
document.write(now.toLocaleString() + "<br>");
function goNaver(){
location.href='http://www.naver.com'; // 이렇게 해도 작동함
}
</script>
</head>
<body>
<!-- location객체의 reload 함수 사용, 새로고침 기능(버튼을 누르면 이 화면에 해당하는 파일을 다시 실행하겠다) -->
<input type="button" value="현재 시간은?" onClick="location.reload()">
<!-- location객체의 href 속성, 페이지를 해당 url로 변경시켜 사이트를 이동함-->
<input type="button" value="다음" onClick="location.href='http://www.daum.net'">
<!-- 바로 위 동작을 함수를 통해 분리해 처리하는 방법인데 결과는 같음-->
<input type="button" value="네이버" onClick="goNaver()">
</body>
</html>