How to encode html code or url to this format?:
\u00253Cb\u002522\....
THANK YOU!
To convert URL to this you need to convert your URL (string) to unicode format
you can try following function for it.
// here toUnicode function is attached to string so that it can used further with
//other strings also
String.prototype.toUnicode = function(){
var result = "";
for(var i = 0; i < this.length; i++){
// Assumption: all characters are < 0xffff
result += "\\u" + ("000" + this[i].charCodeAt(0).toString(16)).substr(-4);
}
return result;
};
let name = "john";
name.toUnicode(); // this will return unicodes of strings
And on another side you can get the Unicode URL using window.location.href (which will be in unicode) you can convert back into string using following function.
// this function coverts the unicode to string char by char
// so you need to loop through the string and call this function a
//nd create resultant string
function unicodeToChar(text) {
return text.replace(/\\u[\dA-F]{4}/gi,
function (match) {
return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16));
});
}