URL()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2021ë 4ì.
URL() ìì±ìë 매ê°ë³ìë¡ ì ê³µí URLì ëíë´ë ìë¡ì´ URL ê°ì²´ë¥¼ ë°íí©ëë¤.
주ì´ì§ ê¸°ì¤ URLì´ë ê²°ê³¼ URLì´ ì í¨íì§ ìì URLì¼ ê²½ì°, JavaScript TypeError ìì¸ê° ë°ìí©ëë¤.
ì°¸ê³ : ì´ ê¸°ë¥ì Web Workerìì ì¬ì©í ì ììµëë¤.
구문
const url = new URL(url [, base])
매ê°ë³ì
url-
ì ë ëë ìë URLì ëíë´ë
USVString.urlì´ ìë URLì¸ ê²½ì°base매ê°ë³ì를 ê¸°ì¤ URLë¡ ì¬ì©íë¯ë¡baseë íìë¡ ì§ì í´ì¼ í©ëë¤. ì ë URLì¸ ê²½ì°baseë 무ìí©ëë¤. baseOptional-
url매ê°ë³ìê° ìë URLì¸ ê²½ì° ì¬ì©í ê¸°ì¤ URLì ëíë´ëUSVString. 기본ê°ì''ì ëë¤.
ìì¸
| ìì¸ | ì¤ëª |
|---|---|
TypeError |
ì ë URLì¸ ê²½ì° url, ìë URLì¸ ê²½ì° base + urlì´ ì í¨íì§ ìì URLì¸ ê²½ì°. |
ìì
// Base urls
let m = "https://developer.mozilla.org";
let a = new URL("/", m); // => 'https://developer.mozilla.org/'
let b = new URL(m); // => 'https://developer.mozilla.org/'
new URL("en-US/docs", b); // => 'https://developer.mozilla.org/en-US/docs'
let d = new URL("/en-US/docs", b); // => 'https://developer.mozilla.org/en-US/docs'
new URL("/en-US/docs", d); // => 'https://developer.mozilla.org/en-US/docs'
new URL("/en-US/docs", a); // => 'https://developer.mozilla.org/en-US/docs'
new URL("/en-US/docs", "https://developer.mozilla.org/fr-FR/toto");
// => 'https://developer.mozilla.org/en-US/docs'
new URL("/en-US/docs", ""); // Raises a TypeError exception as '' is not a valid URL
new URL("/en-US/docs"); // Raises a TypeError exception as '/en-US/docs' is not a valid URL
new URL("http://www.example.com"); // => 'http://www.example.com/'
new URL("http://www.example.com", b); // => 'http://www.example.com/'
new URL("//foo.com", "https://example.com"); // => 'https://foo.com' (see relative URLs)
ëª ì¸
| Specification |
|---|
| URL > # dom-url-url > |
ë¸ë¼ì°ì í¸íì±
ê°ì´ 보기
- ìì±ìê° ìí
URLì¸í°íì´ì¤.