자바스크립트의 Window 객체는 브라우저 창이나 프레임을 나타내는 중요한 객체다.
이 객체는 다양한 속성과 메서드를 제공하며, 그 중 navigation 속성은 브라우저의 이력을 관리하고 탐색하는 데 사용된다.
특히, window.navigation.entries() 매서드는 기존 브라우저에서 보안 문제로 확인할 수 없었던 브라우저 히스토리를 배열로 반환해주는 매소드이다.
window.navigation.entries() // (2) [NavigationHistoryEntry, NavigationHistoryEntry]
NavigationHistoryEntry는 id, index, key, ondispose, sameDocument, url과 같은 중요한 정보들을 가지고 있다.
그 외에도 back, forward, reload와 같은 메서드를 제공한다.
window.navigation.back(); // 브라우저의 이전 페이지로 이동
window.navigation.forward(); // 브라우저의 다음 페이지로 이동
window.navigation.reload(); // 현재 페이지를 새로고침
그 외에도 currentEntry, canGoBack, canGoForward등 여러가지 기능들이 있으므로, 잘 활용한다면 웹 어플리케이션의 사용자 경험을 높이는데 사용될 수 있다.
다만, 비교적 최신 자바스크립트 문법이므로 브라우저 지원 버전을 잘 확인해야 한다.
😎 참고 자료
https://developer.mozilla.org/en-US/docs/Web/API/Window/navigation
Window: navigation property - Web APIs | MDN
The navigation read-only property of the Window interface returns the current window's associated Navigation object.
developer.mozilla.org
'JavaScript' 카테고리의 다른 글
번들러 Rollup 세팅해보기 (1) | 2024.06.07 |
---|---|
commander.js를 사용한 js CLI 라이브러리 구현 (with 예제) (0) | 2024.06.04 |
자바스크립트 primitive types은 garbage collecting될까? (0) | 2024.01.14 |
Web animations API 사용하기 (animate) (0) | 2023.12.11 |
사이트에서 나가시겠습니까? 묻기 (1) | 2023.11.12 |