decodeURIComponent()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Метод decodeURIComponent() декодирует управляющие последовательности символов в компоненте Uniform Resource Identifier (URI), созданные с помощью метода encodeURIComponent или другой подобной процедуры.

Интерактивный пример

function containsEncodedComponents(x) {
  // ie ?,=,&,/ etc
  return decodeURI(x) !== decodeURIComponent(x);
}

console.log(containsEncodedComponents("%3Fx%3Dtest")); // ?x=test
// Expected output: true

console.log(containsEncodedComponents("%D1%88%D0%B5%D0%BB%D0%BB%D1%8B")); // шеллы
// Expected output: false

Синтаксис

decodeURIComponent(encodedURI)

Параметры

encodedURI

Строка, содержащая закодированный компонент Uniform Resource Identifier.

Возвращаемое значение

Новая строка, представляющая собой декодированную версию компонента Uniform Resource Identifier (URI), переданного в качестве параметра.

Исключения

При неправильном использовании выдаёт исключение URIError ("неверный формат последовательности URI").

Описание

Заменяет каждую управляющую последовательность в закодированном компоненте URI соответствующим ей символом.

Примеры

Декодирование компонента кириллического URL

js
decodeURIComponent("JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");
// "JavaScript_шеллы"

Перехват ошибок

js
try {
  var a = decodeURIComponent("%E0%A4%A");
} catch (e) {
  console.error(e);
}

// URIError: malformed URI sequence

Спецификации

Specification
ECMAScript® 2025 Language Specification
# sec-decodeuricomponent-encodeduricomponent

Совместимость с браузерами

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
decodeURIComponent

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Смотрите также