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/document/location/index.html | 91 ++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 files/zh-cn/web/api/document/location/index.html (limited to 'files/zh-cn/web/api/document/location') diff --git a/files/zh-cn/web/api/document/location/index.html b/files/zh-cn/web/api/document/location/index.html new file mode 100644 index 0000000000..bd6429ccab --- /dev/null +++ b/files/zh-cn/web/api/document/location/index.html @@ -0,0 +1,91 @@ +--- +title: Document.location +slug: Web/API/Document/location +translation_of: Web/API/Document/location +--- +

{{APIRef}}

+

Document.location 是一个只读属性,返回一个 {{domxref("Location")}} 对象,包含有文档的 URL 相关的信息,并提供了改变该 URL 和加载其他 URL 的方法。

+

尽管 Document.location 是一个只读的 Location 对象,你也能够赋给它一个 {{domxref("DOMString")}}。这意味着你能够赋给 document.location 字符串,大多数情况下像这样使用:document.location = 'http://www.example.com',也可写为document.location.href = 'http://www.example.com'

+

只是想获取字符串形式的 URL,可以使用只读属性 {{domxref("document.URL")}}。

+

If the current document is not in a browsing context, the returned value is null.

+

语法

+
locationObj = document.location
+document.location = 'http://www.mozilla.org' // Equivalent to document.location.href = 'http://www.mozilla.org'
+
+

示例

+
dump(document.location);
+// Prints a string like
+// "http://www.example.com/juicybits.html" to the console
+
+

规范

+ + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('HTML WHATWG', "history.html#the-location-interface", "Document.location")}}{{Spec2('HTML WHATWG')}}No change from {{SpecName("HTML5 W3C")}}.
{{SpecName('HTML5 W3C', "browsers.html#the-location-interface", "Document.location")}}{{Spec2('HTML5 W3C')}}Initial definition.
+

浏览器兼容性

+

{{CompatibilityTable}}

+
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+
+ + + + + + + + + + + + + + + + + + + +
FeatureAndroidFirefox Mobile (Gecko)IE PhoneOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+

相关链接

+ +

 

-- cgit v1.2.3-54-g00ecf