이 번역은 완료되지 않았습니다. 이 문서를 번역해 주세요.

Location 인터페이스는 객체가 연결된 장소(URL)를 표현합니다. Location 인터페이스에 변경을 가하면 연결된 객체에도 반영되는데, DocumentWindow 인터페이스가 이런 Location을 가지고 있습니다. 각각 Document.locationWindow.location으로 접근할 수 있습니다.

속성

Location 인터페이스는 아무 속성도 상속하지 않지만, URLUtils의 속성을 구현합니다.

Location.href
온전한 URL을 값으로 하는 DOMString입니다. 바뀔 경우 연결된 문서도 새로운 페이지로 이동합니다. 연결된 문서와 다른 오리진에서도 설정할 수 있습니다.
Location.protocol
URL의 프로토콜 부분을 값으로 하는 DOMString으로, 마지막의 ':'도 포함합니다.
Location.host
URL의 호스트 부분을 값으로 하는 DOMString으로, 호스트명, ':', 포트 번호를 포함합니다.
Location.hostname
URL의 도메인 부분을 값으로 하는 DOMString입니다.
Location.port
URL의 포트 번호를 값으로 하는 DOMString입니다.
Location.pathname
'/' 문자 뒤 URL의 경로를 값으로 하는 DOMString입니다.
Location.search
'?' 문자 뒤 URL의 쿼리스트링을 값으로 하는 DOMString입니다. 모던 브라우저에서는 URLSearchParams.get()URL.searchParams를 사용해서 인자를 쉽게 추출할 수 있습니다.
Location.hash
'#' 문자 뒤 URL의 프래그먼트 식별자를 값으로 하는 DOMString입니다.
Location.username
도메인 이름 이전에 명시된 사용자명을 값으로 하는 DOMString입니다.
Location.password
도메인 이름 이전에 명시된 비밀번호를 값으로 하는 DOMString입니다.
Location.origin Read only
지정한 장소 오리진의 표준 형태를 값으로 하는 DOMString입니다.

메서드

Location 인터페이스는 아무 메서드도 상속하지 않지만, URLUtils의 메서드를 구현합니다.

Location.assign()
주어진 URL의 리소스를 불러옵니다.
Location.reload()
현재 URL의 리소스를 다시 불러옵니다. 선택적으로 매개변수에 true를 제공해 브라우저 캐시를 무시하고 서버에서 새로 불러올 수 있습니다,
Location.replace()
Replaces the current resource with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session History, meaning the user won't be able to use the back button to navigate to it.
Location.toString()
Returns a DOMString containing the whole URL. It is a synonym for URLUtils.href, though it can't be used to modify the value.

예제

// 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:8080/en-US/search?q=URL#search-results-close-container';
console.log(url.href);      // https://developer.mozilla.org:8080/en-US/search?q=URL#search-results-close-container
console.log(url.protocol);  // https:
console.log(url.host);      // developer.mozilla.org:8080
console.log(url.hostname);  // developer.mozilla.org
console.log(url.port);      // 8080
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:8080

명세

Specification Status Comment
HTML Living Standard
The definition of 'Location' in that specification.
Living Standard No change from HTML5.
HTML5
The definition of 'Location' in that specification.
Recommendation Initial definition.

브라우저 호환성

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
LocationChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android ? Edge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
assignChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
hashChrome Full support YesEdge Full support 12Firefox Full support 22IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
hostChrome Full support YesEdge Full support 12Firefox Full support 22IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
hostnameChrome Full support YesEdge Full support 12Firefox Full support 22IE No support NoOpera No support NoSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
hrefChrome Full support YesEdge Full support 12Firefox Full support 22IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
originChrome Full support YesEdge Full support 12Firefox Full support 26
Notes
Full support 26
Notes
Notes Before Firefox 49, results for URL using the blob scheme incorrectly returned null.
IE Full support 11
Notes
Full support 11
Notes
Notes Intranet sites are set to Compatibility View, which will emulate IE7 and omit window.location.origin.
Opera Full support 10Safari Full support Yes
Notes
Full support Yes
Notes
Notes According to Apple's documentation, window.location.origin is supported since Safari 10 (both desktop and mobile), but the feature seems to be present in some older versions as well. Because of this, the exact versions supporting this feature cannot be determined reliably.
WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 26
Notes
Full support 26
Notes
Notes Before Firefox 49, results for URL using the blob scheme incorrectly returned null.
Opera Android ? Safari iOS Full support 5Samsung Internet Android ?
passwordChrome Full support YesEdge ? Firefox Full support 26IE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 26Opera Android ? Safari iOS ? Samsung Internet Android ?
pathnameChrome Full support YesEdge Full support 12Firefox Full support 22
Notes
Full support 22
Notes
Notes Before Firefox 53, the pathname property returned wrong parts of the URL. For example, for a URL of http://z.com/x?a=true&b=false, pathname would return "/x?a=true&b=false" rather than "/x".
IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22
Notes
Full support 22
Notes
Notes Before Firefox 53, the pathname property returned wrong parts of the URL. For example, for a URL of http://z.com/x?a=true&b=false, pathname would return "/x?a=true&b=false" rather than "/x".
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
portChrome Full support YesEdge Full support 12Firefox Full support 22IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
protocolChrome Full support YesEdge Full support 12Firefox Full support 22IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
reloadChrome Full support YesEdge Full support 12
Notes
Full support 12
Notes
Notes If a page added to Trusted Sites contains a cross-origin iframe, then calling reload() from within the iframe reloads the trusted page (in other words, the top page reloads, not the iframe).
Firefox Full support YesIE Full support Yes
Notes
Full support Yes
Notes
Notes If a page added to Trusted Sites contains a cross-origin iframe, then calling reload() from within the iframe reloads the trusted page (in other words, the top page reloads, not the iframe).
Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
replaceChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
searchChrome Full support YesEdge Full support 12Firefox Full support 22
Notes
Full support 22
Notes
Notes Before Firefox 53, the search property returned wrong parts of the URL. For example, for a URL of http://z.com/x?a=true&b=false, search would return "", rather than "?a=true&b=false".
IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 22
Notes
Full support 22
Notes
Notes Before Firefox 53, the search property returned wrong parts of the URL. For example, for a URL of http://z.com/x?a=true&b=false, search would return "", rather than "?a=true&b=false".
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
toStringChrome Full support 52Edge Full support YesFirefox Full support 22IE Full support 11
Notes
Full support 11
Notes
Notes Intranet sites are set to Compatibility View, which will emulate IE7 and omit window.location.toString.
Opera ? Safari ? WebView Android Full support 52Chrome Android Full support 52Edge Mobile Full support YesFirefox Android Full support 22Opera Android ? Safari iOS ? Samsung Internet Android ?
usernameChrome Full support YesEdge ? Firefox Full support 26IE ? Opera ? Safari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 26Opera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.

같이 보기

문서 태그 및 공헌자

이 페이지의 공헌자: alattalatta
최종 변경자: alattalatta,