encodeURIComponent

encodeURIComponentencodeURIComponent(uri)
Replaces special characters in a URI with escape sequences.