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

URL 인터페이스는 객체 URL들을 만드는 데 사용되는 정적 메서드를 제공하는 객체를 나타낸다.
 

When using a user agent where no constructor has been implemented yet, it is possible to access such an object using the Window.URL properties (prefixed with Webkit-based browser as Window.webkitURL).

주의: This feature is available in Web Workers.

Usage

URL은 URL을 구문 분석, 구성, 정규화 및 인코딩하는 데 사용된다.

생성자는 url  매개 변수를 사용하고, url 매개 변수가 상대 URL 인 경우 선택적으로 base 매개 변수를 기본으로 사용한다.

const url = new URL('../cats', 'http://www.example.com/cats');
console.log(url.hostname); // "www.example.com"
console.log(url.pathname); // "/cats"

URL 속성은 URL을 생성하도록 설정할 수 있다.

url.hash = 'tabby';
console.log(url.href); // "http://www.example.com/cats#tabby"

URL들은 RFC 3986에 따라 인코딩이 된다. :

url.pathname = 'démonstration.html';
console.log(url.href); // "http://www.example.com/d%C3%A9monstration.html"

URLSearchParams 인터페이스는 URL query string을 작성하고 조작하는데 사용이 된다.

현재 window's URL에서 검색 매개 변수를 가져오기 위해, 다음과 같이 할 수 있다. :

// https://some.site/?id=123
var parsedUrl = new URL(window.location.href);
console.log(parsedUrl.searchParams.get("id")); // 123

URL의 toString 메소드는 href 속성이다, 그래서 생성자를 사용하여 URL을 정규화하고 직접 인코딩 할 수 있다.

const response = await fetch(new URL('http://www.example.com/démonstration.html'));

Constructor

URL()
지정된 파라미터로 구성된 URL 객체를 만들고 돌려준다.

Properties

URL.hash
USVString은 URL의 fragment 식별자 다음에 '#' 를 포함한다.
URL.host
USVString은 (포트가 있을 경우) ':' 와 URL의 포트 다음에 오는 도메인(호스트이름)을 포함한다. 
URL.hostname
USVString은 도메인(호스트이름)을 포함한다. 
URL.href
USVString은 전체 URL을 포함한다.
URL.origin Read only
URL의 origin, 즉 스키마, 도메인 및 포트를 포함하는 USVString을 반환한다.
URL.password
USVString은 도메인 이름 앞에 지정된 암호가 들어가 있다.
URL.pathname
USVString은 URL의 경로가 뒤 따르는 초기 '/'가 포함되어 있다.
URL.port
USVString은 URL의 포트 숫자를 담고 있다.
URL.protocol
USVString은 마지막에 ':'를 포함한 URL의 프로토콜 스키마를 담고 있다.
URL.search
USVString은 URL의 매개 변수 다음에 '?'를 담고 있다.
URL.searchParams Read only
URL에 포함 된 GET 쿼리 인수에 액세스 할 수있는 URLSearchParams 객체를 반환한다.
URL.username
USVString은 도메인 이름 앞에 지정된 사용자 이름을 포함한다.

Methods

URL.toString()
Returns a USVString containing the whole URL. It is a synonym for URL.href, though it can't be used to modify the value.
URL.toJSON()
Returns a USVString  containing the whole URL. It returns the same string as the href property.

Static methods

URL.createObjectURL()
고유 한 blob URL을 포함하는 DOMString을 반환한다. 이 URL은 브라우저에서 객체를 고유하게 식별하는 불투명 한 문자열 다음에 blob:을 스키마로 갖는 URL입니다.
URL.revokeObjectURL()
URL.createObjectURL()를 사용하여 이전에 만든 object URL을 취소한다.

Specifications

Specification Status Comment
File API
The definition of 'URL' in that specification.
Working Draft Added the static methods URL.createObjectURL() and URL.revokeObjectURL().
URL
The definition of 'API' in that specification.
Living Standard Initial definition (implements URLUtils).

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
URLChrome Full support 32
Full support 32
Full support 2
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge Full support 12Firefox Full support 19
Notes
Full support 19
Notes
Notes Before version 57, Firefox had a bug whereby single quotes contained in URLs are escaped when accessed via URL APIs (see bug 1386683).
Notes To use it from chrome code, JSM and Bootstrap scope, you have to import it with Cu.importGlobalProperties(['URL']);.
IE ? Opera Full support 19
Full support 19
Full support 15
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari Full support 7
Full support 7
Full support 6
Prefixed
Prefixed Implemented with the vendor prefix: webkit
WebView Android Full support 4.4
Full support 4.4
Full support 4
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Chrome Android Full support 32
Full support 32
Full support 18
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge Mobile Full support 12Firefox Android Full support 19
Notes
Full support 19
Notes
Notes Before version 57, Firefox had a bug whereby single quotes contained in URLs are escaped when accessed via URL APIs (see bug 1386683).
Notes To use it from chrome code, JSM and Bootstrap scope, you have to import it with Cu.importGlobalProperties(['URL']);.
Opera Android Full support 19
Full support 19
Full support 14
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS Full support 7
Full support 7
Full support 6
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Samsung Internet Android Full support Yes
URL() constructorChrome Full support YesEdge Full support 12Firefox Full support 26IE No support ? — 11Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support 12Firefox Android Full support 26Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
createObjectURL
Experimental
Chrome Full support 8Edge Full support 12Firefox Full support 19
Notes
Full support 19
Notes
Notes createObjectURL() is no longer available within the context of a ServiceWorker.
IE Full support 10Opera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Edge Mobile ? Firefox Android Full support 19
Notes
Full support 19
Notes
Notes createObjectURL() is no longer available within the context of a ServiceWorker.
Opera Android Full support 14Safari iOS Full support 6Samsung Internet Android Full support Yes
hashChrome Full support YesEdge Full support 13Firefox Full support 22IE ? Opera 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 13Firefox Full support 22IE ? Opera 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 13Firefox Full support 22IE ? Opera Full support YesSafari Full support 10WebView 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
hrefChrome Full support YesEdge Full support 13Firefox Full support 22IE ? Opera Full support YesSafari Full support 10WebView 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 52Edge Full support 12Firefox Full support 26
Full support 26
No support 26 — 49
Notes
Notes Results for URL using the blob scheme incorrectly returned null.
IE ? Opera Full support YesSafari Full support 10WebView Android Full support 52Chrome Android Full support 52Edge Mobile Full support 12Firefox Android Full support 26
Full support 26
No support 26 — 49
Notes
Notes Results for URL using the blob scheme incorrectly returned null.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
passwordChrome Full support 52Edge Full support 12Firefox Full support 26IE ? Opera Full support YesSafari Full support 10WebView Android Full support 52Chrome Android Full support 52Edge Mobile Full support 12Firefox Android Full support 26Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
pathnameChrome Full support YesEdge Full support 13Firefox Full support 53
Full support 53
No support 22 — 53
Notes
Notes pathname and search returned the wrong values so that for a URL of http://z.com/x?a=true&b=false, pathname would return "/x?a=true&b=false" and search would return "", rather than "/x" and "?a=true&b=false" respectively.
IE ? Opera Full support YesSafari Full support 10WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 53
Full support 53
No support 22 — 53
Notes
Notes pathname and search returned the wrong values so that for a URL of http://z.com/x?a=true&b=false, pathname would return "/x?a=true&b=false" and search would return "", rather than "/x" and "?a=true&b=false" respectively.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
portChrome Full support YesEdge Full support 13Firefox Full support 22IE ? Opera Full support YesSafari Full support 10WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 22Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
protocolChrome Full support YesEdge Full support 13Firefox Full support 22IE ? Opera Full support YesSafari Full support 10WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 22Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
revokeObjectURL
Experimental
Chrome Full support 8Edge Full support 12Firefox Full support 19
Notes
Full support 19
Notes
Notes revokeObjectURL() is no longer available within the context of a ServiceWorker.
IE Full support 10Opera Full support 15Safari Full support 6WebView Android Full support YesChrome Android Full support 18Edge Mobile ? Firefox Android Full support 19
Notes
Full support 19
Notes
Notes revokeObjectURL() is no longer available within the context of a ServiceWorker.
Opera Android Full support 14Safari iOS Full support 6Samsung Internet Android Full support Yes
searchChrome Full support YesEdge Full support 13Firefox Full support 53
Full support 53
No support 22 — 53
Notes
Notes pathname and search returned the wrong values so that for a URL of http://z.com/x?a=true&b=false, pathname would return "/x?a=true&b=false" and search would return "", rather than "/x" and "?a=true&b=false" respectively.
IE ? Opera Full support YesSafari Full support 10WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 53
Full support 53
No support 22 — 53
Notes
Notes pathname and search returned the wrong values so that for a URL of http://z.com/x?a=true&b=false, pathname would return "/x?a=true&b=false" and search would return "", rather than "/x" and "?a=true&b=false" respectively.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
searchParamsChrome Full support 51Edge Full support 17Firefox Full support 29IE No support NoOpera Full support YesSafari Full support 10WebView Android Full support 51Chrome Android Full support 51Edge Mobile ? Firefox Android Full support 29Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
toJSONChrome Full support 71Edge Full support 17Firefox Full support 54IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 71Chrome Android Full support 71Edge Mobile ? Firefox Android Full support 54Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
toStringChrome Full support 52Edge Full support 17Firefox Full support 54IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support 52Chrome Android Full support 52Edge Mobile ? Firefox Android Full support 54Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
usernameChrome Full support 52Edge Full support 12Firefox Full support 26IE ? Opera Full support YesSafari Full support 10WebView Android Full support 52Chrome Android Full support 52Edge Mobile Full support 12Firefox Android Full support 26Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

See also

문서 태그 및 공헌자

이 페이지의 공헌자: mdnwebdocs-bot, SeonHyungJo, alattalatta, yuj25
최종 변경자: mdnwebdocs-bot,