Forum Moderators: open

Message Too Old, No Replies

unescape() is deprecated, do I need decodeURI()?

         

csdude55

5:35 am on Aug 22, 2023 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've been using this for years (decades?) to find the value of a cookie:

function getCookie(c_name) {
if (document.cookie.length > 0) {
c_start = document.cookie.indexOf(c_name + '=');

if (c_start != -1) {
c_start = c_start + c_name.length+1;
c_end = document.cookie.indexOf(';',c_start);

if (c_end == -1) c_end = document.cookie.length;

return unescape(document.cookie.substring(c_start, c_end));
}
}

return '';
}


I just discovered that unescape() is deprecated:

[developer.mozilla.org...]

But I honestly don't know why I used it in the first place.

Would you recommend using decodeURI() or decodeURIComponent() instead? What would be the danger of just returning document.cookie.substring(c_start, c_end)?