Encode URL with encodeURIComponent

Description

encodeURIComponent() methods is used to encode URIs to be passed to the browser.

encodeURIComponent() is designed to work solely on a segment of a URI.

encodeURIComponent() encodes every nonstandard character.

Example


var uri = "http://www.java2s.com/illegal value.htm#start";
console.log(encodeURIComponent(uri));

The code above generates the following result.





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window