DOM PageTransitionEvent는 사용자가 웹페이지 사이를 이동할 때 발생하는 이벤트입니다.
PageTransitionEvent 개체의 속성
| 속성 | 설명 |
|---|---|
| 지속됨 | 웹 페이지가 캐시되었는지 여부에 따라 true 또는 false 값을 반환합니다. |
PageTransitionEvent 개체에 속하는 이벤트 유형
| 이벤트 | 설명 |
|---|---|
| 페이지 숨기기 | 사용자가 웹페이지에서 다른 곳으로 이동할 때 발생합니다. |
| 페이지 표시 | 사용자가 웹페이지로 이동할 때 발생합니다. |
예시
PageTransitionEvent 객체의 예를 살펴보겠습니다 -
<!DOCTYPE html>
<html>
<head>
<style>
body{
text-align:center;
color:#fff;
background: #ff7f5094;
height:100%;
}
.btn{
background:#0197F6;
border:none;
height:2rem;
border-radius:2px;
width:35%;
margin:2rem auto;
display:block;
color:#fff;
outline:none;
cursor:pointer;
}
</style>
</head>
<body>
<h1>DOM PageTransitionEvent Event Demo</h1>
<button onclick="checkPage(event)" class="btn">Click me</button>
<script>
function checkPage(event) {
if (event.persisted) {
confirm("Page was cached by the browser");
} else {
confirm("Page was not cached by the browser");
}
}
</script>
</body>
</html> 출력
이것은 다음과 같은 출력을 생성합니다 -

"나를 클릭하세요를 클릭하세요. " 버튼을 눌러 페이지가 브라우저에 의해 캐시되었는지 여부를 알 수 있습니다.
