URL()
Experimental
Это экспериментальная технология
Так как спецификация этой технологии ещё не стабилизировалась, смотрите таблицу совместимости по поводу использования в различных браузерах. Также заметьте, что синтаксис и поведение экспериментальной технологии может измениться в будущих версиях браузеров, вслед за изменениями спецификации.
Конструктор URL()
возвращает вновь созданный URL
объект отражающий URL определяемый параметрами.
If the given base URL or the resulting URL are not valid URLs, a DOMException
(en-US) of type SYNTAX_ERROR
is thrown.
Примечание: Эта возможность доступна в Web Workers.
Синтаксис
url = new URL(urlString, [baseURLstring]) url = new URL(urlString, baseURLobject)
Параметры
- urlString
- Is a
DOMString
representing an absolute or relative URL. If urlString is a relative URL, baseURLstring or baseURLobject, whichever is present, will be used as the base URL. If urlString is an absolute URL, baseURLstring and baseURLobject are ignored. - baseURLstring Необязательный
- Is a
DOMString
representing the base URL to use in case urlString is a relative URL. If not specified, and no baseURLobject is passed in parameters, it default to'about:blank'
. If it is an invalid absolute URL, the constructor will raise aDOMException
(en-US) of typeSYNTAX_ERROR
- baseURLobject
- Is a
URL
object representing the base URL to use in case urlString is a relative URL.
Примеры
var a = new URL("/", "https://developer.mozilla.org"); // Creates a URL pointing to 'https://developer.mozilla.org/'
var b = new URL("https://developer.mozilla.org"); // Creates a URL pointing to 'https://developer.mozilla.org/'
var c = new URL('en-US/docs', b); // Creates a URL pointing to 'https://developer.mozilla.org/en-US/docs'
var d = new URL('/en-US/docs', b); // Creates a URL pointing to 'https://developer.mozilla.org/en-US/docs'
var f = new URL('/en-US/docs', d); // Creates a URL pointing to 'https://developer.mozilla.org/en-US/docs'
var g = new URL('/en-US/docs', "https://developer.mozilla.org/fr-FR/toto");
// Creates a URL pointing to 'https://developer.mozilla.org/en-US/docs'
var h = new URL('/en-US/docs', a); // Creates a URL pointing to 'https://developer.mozilla.org/en-US/docs'
var i = new URL('/en-US/docs', ''); // Raises a SYNTAX ERROR exception as '/en-US/docs' is not valid
var j = new URL('/en-US/docs'); // Raises a SYNTAX ERROR exception as 'about:blank/en-US/docs' is not valid
var k = new URL('http://www.example.com', 'https://developers.mozilla.com');
// Creates a URL pointing to 'http://www.example.com/'
var l = new URL('http://www.example.com', b); // Creates a URL pointing to 'http://www.example.com/'
Спецификация
Specification | Status | Comment |
---|---|---|
URL Определение 'URL.URL()' в этой спецификации. |
Живой стандарт | Initial definition. |
Поддержка браузерами
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Да) | 26.0 (26.0) | Нет | (Да) | (Да) |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | 26.0 (26.0) | Нет | ? | (Да) |
Смотрите также
- The interface it belongs to:
URL
.