From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/window/history/index.html | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 files/zh-cn/web/api/window/history/index.html (limited to 'files/zh-cn/web/api/window/history') diff --git a/files/zh-cn/web/api/window/history/index.html b/files/zh-cn/web/api/window/history/index.html new file mode 100644 index 0000000000..118bfe284c --- /dev/null +++ b/files/zh-cn/web/api/window/history/index.html @@ -0,0 +1,34 @@ +--- +title: Window.history +slug: Web/API/Window/history +translation_of: Web/API/Window/history +--- +

{{ ApiRef("Window") }}

+ +

Window.history是一个只读属性,用来获取{{domxref("History")}} 对象的引用,{{domxref("History")}} 对象提供了操作浏览器会话历史(浏览器地址栏中访问的页面,以及当前页面中通过框架加载的页面)的接口。

+ +

History对象有如下方法:参见 Manipulating the browser history 中的示例和详情。尤其指出的是文章里解释了在使用pushState()replaceState()方法前,你需要了解的安全问题。

+ +

语法

+ +
var historyObj = window.history;
+ +

示例

+ +
history.back();     // 等同于点击浏览器的回退按钮
+history.go(-1);     //等同于history.back();
+
+ +

附注

+ +

在顶层页面中,浏览器的回退和前进按钮旁的下拉菜单显示了可以通过History对象访问到的页面会话历史(session history)列表。

+ +

出于安全考虑,History对象不允许未授权代码访问会话历史(session History)中其它页面的URLs,但可以导航到其它会话历史(session History)指向的页面。

+ +

未授权代码无法清除会话历史(session History),也不能禁用回退/前进功能。最快捷的可用方式是使用location.replace()方法,提供指定的URL来替换当前的会话历史(session history)。

+ +

规范

+ + -- cgit v1.2.3-54-g00ecf