IT Study/Web

[JavaScript] location.href 기본 예제

도뿌리 2018. 8. 6. 14:33

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 
<a href="NewFile.html">NewFile.html로 이동</a>
<br>
 
<form action="NewFile.html">
<input type="submit" value="NewFile.html로 이동">
</form>
<br>
 
<button type="button" onclick="myfunc()">버튼</button>
<br>
 
<script type="text/javascript">
 
function myfunc() {
    //스크립트에서 페이지 이동할 때
    location.href = "NewFile.html";
}
</script>
</body>
</html>
cs


HTML에선 action이나 <a>로 페이지를 이동

JavaScript에서도 location.href로 페이지를 이동할 수 있다.