--- title: Location slug: Web/API/Location tags: - API - Interface - Location translation_of: Web/API/Location ---
{{APIRef("URLUtils")}}
Location
接口表示其链接到的对象的位置(URL)。所做的修改反映在与之相关的对象上。 {{domxref("Document")}} 和 {{domxref("Window")}} 接口都有这样一个链接的Location,分别通过 {{domxref("Document.location")}}和{{domxref("Window.location")}} 访问。
Location
接口不继承任何属性,但是实现了那些来自 {{domxref("URLUtils")}} 的属性。
/"。
“?”
。“#”。
Location
没有继承任何方法,但实现了来自{{domxref("URLUtils")}}的方法。
false
或没有制定这个参数,浏览器可能从缓存当中加载页面。assign()
方法不同的是用 replace()
替换的新页面不会被保存在会话的历史 {{domxref("History")}}中,这意味着用户将不能用后退按钮转到该页面。// Create anchor element and use href property for the purpose of this example // A more correct alternative is to browse to the URL and use document.location or window.location var url = document.createElement('a'); url.href = 'https://developer.mozilla.org/en-US/search?q=URL#search-results-close-container'; console.log(url.href); // https://developer.mozilla.org/en-US/search?q=URL#search-results-close-container console.log(url.protocol); // https: console.log(url.host); // developer.mozilla.org console.log(url.hostname); // developer.mozilla.org console.log(url.port); // (blank - https assumes port 443) console.log(url.pathname); // /en-US/search console.log(url.search); // ?q=URL console.log(url.hash); // #search-results-close-container console.log(url.origin); // https://developer.mozilla.org
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "history.html#the-location-interface", "Location")}} | {{Spec2('HTML WHATWG')}} | No change from {{SpecName("HTML5 W3C")}}. |
{{SpecName('HTML5 W3C', "browsers.html#the-location-interface", "Location")}} | {{Spec2('HTML5 W3C')}} | Initial definition. |
{{CompatibilityTable}}
特性 | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
origin on Windows.location |
{{CompatUnknown}} | {{CompatGeckoDesktop("21")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
origin on all location objects (but on Workers, that use {{domxref("WorkerLocation")}} |
{{CompatUnknown}} | {{CompatGeckoDesktop("26")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
username and password |
{{CompatUnknown}} | {{CompatGeckoDesktop("26")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
searchParams |
{{CompatUnknown}} | {{CompatGeckoDesktop("34")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
origin on Windows.location |
{{CompatUnknown}} | {{CompatGeckoMobile("21")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
origin on all location objects (but on Workers, that use {{domxref("WorkerLocation")}}) |
{{CompatUnknown}} | {{CompatGeckoMobile("26")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
username and password |
{{CompatUnknown}} | {{CompatGeckoMobile("26")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
searchParams |
{{CompatUnknown}} | {{CompatGeckoMobile("34")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |