Check out the built-in function encodeURIComponent(str) and encodeURI(str).
In your case, this should work:
var myOtherUrl =
"http://example.com/index.html?url=" + encodeURIComponent(myUrl);
Answer from Buu on Stack OverflowMDN Web Docs
developer.mozilla.org βΊ en-US βΊ docs βΊ Web βΊ JavaScript βΊ Reference βΊ Global_Objects βΊ encodeURIComponent
encodeURIComponent() - JavaScript | MDN
October 30, 2025 - The encodeURIComponent() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two surrogate characters).
Top answer 1 of 16
3239
Check out the built-in function encodeURIComponent(str) and encodeURI(str).
In your case, this should work:
var myOtherUrl =
"http://example.com/index.html?url=" + encodeURIComponent(myUrl);
2 of 16
1710
You have three options:
escape()will not encode:@*/+encodeURI()will not encode:~!@#$&*()=:/,;?+'encodeURIComponent()will not encode:~!*()'
But in your case, if you want to pass a URL into a GET parameter of other page, you should use escape or encodeURIComponent, but not encodeURI.
See Stack Overflow question Best practice: escape, or encodeURI / encodeURIComponent for further discussion.
10:18
JavaScript How to Encode URL - YouTube
02:03
How to Encode a URL in JavaScript (encodeURI vs encodeURIComponent) ...
07:47
π HTML URL Encoding: The Ultimate Beginner's Guide - YouTube
00:53
οΈ EncodeURI & DecodeURI in JavaScript
15:31
What is URL Encoding? - URL Encode/Decode Explained - Web Development ...
08:23
Curso MOOC Node.JS: URL Encode - YouTube
MDN Web Docs
developer.mozilla.org βΊ en-US βΊ docs βΊ Web βΊ JavaScript βΊ Reference βΊ Global_Objects βΊ encodeURI
encodeURI() - JavaScript | MDN
The encodeURI() function encodes a URI by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two surrogate characters).
Eric Meyer
meyerweb.com βΊ eric βΊ tools βΊ dencoder
URL Decoder/Encoder
The URL Decoder/Encoder is licensed under a Creative Commons Attribution-ShareAlike 2.0 License.
W3Schools
w3schools.com βΊ jsref βΊ jsref_encodeuri.asp
JavaScript encodeURI() Method
The encodeURI() method encodes a URI.
DEV Community
dev.to βΊ lico βΊ understanding-how-spaces-are-encoded-20-with-encodeuri-vs-with-url-2d6c
Why Spaces Are Encoded: with encodeURI and +(plus) with URL / Differences Between encodeURI and URL - DEV Community
November 28, 2024 - While I couldn't find the specification in RFC for this behavior, MDN's encodeURIComponent documentation states: For application/x-www-form-urlencoded, spaces are to be replaced by +, so one may wish to follow a encodeURIComponent() replacement with an additional replacement of with +.
URL Encode
urlencoder.org
URL Encode and Decode - Online
Encode to URL-encoded format or decode from it with various advanced options. Our site has an easy to use online tool to convert your data.
D3
d3js.org
D3 by Observable | The JavaScript library for bespoke data visualization
Explain position encodings with axes.
Base64 Encode
base64encode.org
Base64 Encode and Decode - Online
Enable this option to encode into an URL- and filename- friendly Base64 variant (RFC 4648 / Base64URL) where the "+" and "/" characters are respectively replaced by "-" and "_", as well as the padding "=" signs are omitted. Live mode: When you turn on this option the entered data is encoded immediately with your browser's built-in JavaScript functions, without sending any information to our servers.
Net Informations
net-informations.com βΊ js βΊ progs βΊ encode.htm
How to encode a URL using JavaScript?
You can use the built-in method encodeURIComponent() to encode a URL in JavaScript.
MDN Web Docs
developer.mozilla.org βΊ en-US βΊ docs βΊ Web βΊ API βΊ Fetch_API βΊ Using_Fetch
Using the Fetch API - Web APIs | MDN
Other objects are converted to strings using their toString() method. For example, you can use a URLSearchParams object to encode form data (see setting headers for more information):
FFmpeg
ffmpeg.org
FFmpeg
Currently, the only codecs supported are: FFv1 (encoding and decoding) and ProRes RAW (decode only). ProRes (encode+decode) and VC-2 (encode+decode) implementations are complete and currently in review, to be merged soon and available with the next minor release.
Obfuscator
obfuscator.io
JavaScript obfuscator tool - Protect Your JS Code
VM (Virtual Machine) obfuscation transforms your JavaScript code into custom bytecode that runs on an embedded interpreter. Unlike standard obfuscation which still produces readable JavaScript, VM obfuscation completely hides your original code structure. Static analysis tools cannot understand the logic without first reverse-engineering the entire virtual machine.