aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/window/history
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/window/history
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/api/window/history')
-rw-r--r--files/zh-cn/web/api/window/history/index.html34
1 files changed, 34 insertions, 0 deletions
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
+---
+<p>{{ ApiRef("Window") }}</p>
+
+<p><strong><code>Window.history</code></strong>是一个只读属性,用来获取{{domxref("History")}} 对象的引用,{{domxref("History")}} 对象提供了操作浏览器<em>会话历史</em>(浏览器地址栏中访问的页面,以及当前页面中通过框架加载的页面)的接口。</p>
+
+<p><code>History</code>对象有如下方法:参见<span style="line-height: 1.5;"> </span><a href="/zh-CN/docs/Web/API/History_API" style="line-height: 1.5;" title="en/DOM/Manipulating the browser history">Manipulating the browser history</a><span style="line-height: 1.5;"> 中的示例和详情。尤其指出的是文章里解释了在使用<code>pushState()</code>和<code>replaceState()方法前,你需要了解的安全问题。</code></span></p>
+
+<h2 id="Syntax" name="Syntax">语法</h2>
+
+<pre class="syntaxbox"><em>var historyObj</em> = <em>window</em>.history;</pre>
+
+<h2 id="Example" name="Example">示例</h2>
+
+<pre class="brush: js">history.back(); // 等同于点击浏览器的回退按钮
+history.go(-1); //等同于history.back();
+</pre>
+
+<h2 id="Notes" name="Notes">附注</h2>
+
+<p>在顶层页面中,浏览器的回退和前进按钮旁的下拉菜单显示了可以通过<code>History</code>对象访问到的页面会话历史(session history)列表。</p>
+
+<p>出于安全考虑,History对象不允许未授权代码访问会话历史(session History)中其它页面的URLs,但可以导航到其它会话历史(session History)指向的页面。</p>
+
+<p>未授权代码无法清除会话历史(session History),也不能禁用回退/前进功能。最快捷的可用方式是使用<a href="/en/DOM/window.location#replace" style="font-family: 'Courier New', 'Andale Mono', monospace; line-height: normal;" title="en/DOM/window.location#replace">location.replace()</a>方法,提供指定的URL来替换当前的会话历史(session history)。</p>
+
+<h2 id="Specification" name="Specification">规范</h2>
+
+<ul>
+ <li><a class="external" href="http://whatwg.org/html#the-history-interface">HTML5 History interface</a></li>
+</ul>