decodeURIComponent()
function decodes a Uniform Resource Identifier (URI) component previously created by
encodeURIComponent
or by a similar routine.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
decodeURIComponent(encodedURI)
encodedURI
An encoded component of a Uniform Resource Identifier.
A new string representing the decoded version of the given encoded Uniform Resource Identifier (URI) component.
Throws an
URIError
("malformed URI sequence") exception when used wrongly.
Replaces each escape sequence in the encoded URI component with the character that it represents.
decodeURIComponent('JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B');
// "JavaScript_шеллы"
try {
var a = decodeURIComponent('%E0%A4%A');
} catch(e) {
console.error(e);
}
// URIError: malformed URI sequence
decodeURIComponent cannot be used directly to parse query parameters from a URL. It needs a bit of preparation.
function decodeQueryParam(p) {
return decodeURIComponent(p.replace(/\+/g, ' '));
}
decodeQueryParam('search+query%20%28correct%29');
// 'search query (correct)'
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'decodeURIComponent' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
decodeURIComponent
|
Chrome 1 | Edge 12 | Firefox 1 | IE 5.5 | Opera 7 | Safari 1.1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
完整支持