i have a value
abc}efg
i need it to pass from URL
in HTML } = }
in URL } = %7D
how to convert }
to %7D
?
i have a value
abc}efg
i need it to pass from URL
in HTML } = }
in URL } = %7D
how to convert }
to %7D
?
encodeURIComponent
combined with How to decode HTML entities using jQuery?.
jQuery's .html()
function is basically a thin function wrapper around the widely-supported (vanilla DOM) innerHTML
property, so the linked question is still applicable if you're not using jQuery.
The function was named encodeURIComponent, and fortunately it's a built-in funciton. You can use it for free:
alert( encodeURIComponent("}") ) //-- alert box will show "%7D"
It sounds like you want to:
So, first of all, I'd recommend an Entity dictionary like this excellent one: http://www.strictly-software.com/scripts/downloads/encoder.js
This should help you out from there:
function browerURLtoEntity( code ) {
var crypt = {};
crypt.URI = code;
crypt.ascii = decodeURLComponent(crypt.URI);
crypt.entity = Encoder.htmlEncode(crypt.ascii);
return crypt;
}
// crypt.entity will be the piece that you want.