window.history 객체

Mia Lee·2021년 11월 26일
0

Java Script

목록 보기
14/25
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	/*
	window.history 객체
	- 웹브라우저의 주소 기록(= 방문 기록)을 관리하는 객체
	- 브라우저를 통해 접속했던 주소 정보를 차례대로 저장하고 관리
	- 속성 : history.length
	  함수 : history.back(), history.forward(), history.go()
	*/
	function func1() {
		// 현재 웹브라우저에 저장된 방문기록 갯수 확인
		alert(history.length);
	}

	function func2() {
		// 현재 웹페이지에서 이전 페이지로 이동(= 뒤로 가기) => 1단계 (중요!!!!)
		history.back();
	}

	function func3() {
		// 현재 웹페이지에서 다음 페이지로 이동(= 앞으로 가기) => 1단계
		history.forward();
	}

	function func4() {
		// 현재 웹페이지에서 x번째 이전 페이지로 이동 => x단계
		history.go(-2); // 반드시 음수값 전달
		// => history.back() 과 history.go(-1) 은 동일
	}

	function func5() {
		// 현재 웹페이지에서 x번째 다음 페이지로 이동 => x단계
		history.go(2); // 반드시 양수값 전달
	}
	
</script>
</head>
<body>
	<input type="button" value="방문기록 갯수 확인" onclick="func1()"><br>
	<input type="button" value="이전페이지" onclick="func2()"><br>
	<input type="button" value="다음페이지" onclick="func3()"><br>
	<input type="button" value="2단계 이전페이지" onclick="func4()"><br>
	<input type="button" value="2단계 다음페이지" onclick="func5()"><br>
</body>
</html>

0개의 댓글