Breaking

Search Here

05 January 2018

W3 Schools Articles





JavaScript decodeURI()

Example

Decode a URI after encoding it:

let uri = "my test.asp?name=ståle&car=saab";
let encoded = encodeURI(uri);
let decoded = decodeURI(encoded);
Definition and Usage
The decodeURI() method decodes a URI.

Note
Use the encodeURI() method to encode a URI

See Also:
The encodeURIComponent() method to encode a URI

The decodeURIComponent() method to decode a URI

Syntax
decodeURI(uri)
Parameters
Parameter Description
uri                 Required.

The URI to decode.
Return Value
Type Description
A string The decoded URI.
Browser Support
decodeURI() is an ES1 feature (JavaScript 1997). It is fully supported in all browsers:

Chrome

IE           Yes

Edge   Yes

Firefox   Yes

Safari   Yes

Opera        Yes

all are browsers supported

1. Overview of encodeURI() function

The encodeURI() function is used to encode a URI.
This function encodes special characters, except: , / ? : @ & = + $ # (Use encodeURIComponent() to encode these characters).
Note : Use the decodeURI() function to decode an encoded URI.

2. Overview of decodeURI() function

The decodeURI() function is used to decode a URI.
Note: Use the encodeURI() function to encode a URI.

3. encodeURI() and decodeURI() function 

example

Let's first encode using encodeURI() method and then decode it using decodeURI() function.
var uri = 'https://javaguides.net/?x=шеллы';
console.log("before encode :: " + uri);
var encoded = encodeURI(uri);
console.log("after encode :: " + encoded);
try {
    var decoded = decodeURI(encoded);
    console.log();
    console.log("after decode :: " + decoded);
} catch(e) { // catches a malformed URI
    console.error(e);
}


Output:

before encode :: https://javaguides.net/?x=шеллы
after encode :: https://javaguides.net/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B
after decode :: https://javaguides.net/?x=шеллы

No comments:

Post a Comment

Hello all, if you have any doubt feel free comment

Comments