HTML DOM PageTransition 事件
htmlweb developmentfront end technology更新于 2025/9/18 23:08:17
DOM PageTransitionEvent 是用户在网页之间导航时发生的事件。
PageTransitionEvent 对象的属性
| 属性 | 说明 |
|---|---|
| persisted | 根据网页是否缓存,返回 true 或 false 值。 |
属于 PageTransitionEvent 的事件类型对象
| 事件 | 说明 |
|---|---|
| pageHide | 当用户离开网页时发生。 |
| pageShow | 当用户导航到网页时发生。 |
示例
来看一个例子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>
输出
这将产生以下输出 −

点击"点击我"按钮可以查看该页面是否已被浏览器缓存。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

