JavaScript 中的 window.history 对象的作用是什么?
window.history 对象用于在 Web 浏览器的页面之间前进后退。它拥有浏览器的历史记录,包含以下两个方法 −
- history.back − 返回上一个 URL
- history.next − 前往下一个 URL
示例
你可以尝试运行以下代码,了解如何在 JavaScript 中使用 window.history 对象 −
<!DOCTYPE html>
<html>
<body>
<script>
function backPage() {
window.history.back()
}
function nextPage() {
window.history.next()
}
</script>
<input type="button" value="Previous URL" onclick="backPage()">
<input type="button" value="Next URL" onclick="nextPage()">
</body>
</html>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP