I'm having problems encoding a string so I can place a variable into a link. I'm sure this is really simple, but i had trouble turning anything up.
$("a.inquiry").attr("href", "/inquiry/6933/text=" + encodeURI("text o"));
This doesn't work.
encodeURI("text o")
Still returns:
link/text o
Instead of:
link/text%20
Also tried:
$("a.inquiry").attr("href", encodeURIComponent("/inquiry/6933/text=" + "text o"));
If you have a complete URL, use encodeURI . But if you have a part of a URL, use encodeURIComponent .
Return valueA new string representing the provided string encoded as a URI.
The encodeURIComponent function is used to encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two or three escape sequences representing the UTF-8 encoding of the character.
1. decodeURI function: The decodeURI() function is used to decode URI generated by encodeURI(). Parameters: This function accepts a single parameter complete_encoded_uri_string which holds the encoded string. Return Value: This function returns the decoded string (original string).
Try with encodeURIComponent
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With