HTML DOM PageTransition 事件
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>输出
它将产生以下输出 -

点击“单击我”按钮以了解浏览器是否缓存了当前页面。

广告
数据结构
网络
关系型数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP