James_Parsons Posted January 9, 2013 Share Posted January 9, 2013 I was looking through one of my web dev books when I found a javascript function I just didn't get. it was used in a cookie that stored info about radio buttons chosen. the function is escape() and here is the line document.cookie="optFont=" +escape(fontChoice)+";expires="+expire.toUTCString(); can anyone tell me what this function does and some common uses Link to comment Share on other sites More sharing options...
justsomeguy Posted January 9, 2013 Share Posted January 9, 2013 escape and unescape shouldn't be used anymore, but there is a description here along with the better alternatives: https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Functions?redirectlocale=en-US&redirectslug=Core_JavaScript_1.5_Guide%2FFunctions#escape_and_unescape_functions For the example above, encodeURIComponent would be the function to use instead. https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURIComponent 1 Link to comment Share on other sites More sharing options...
jeffman Posted January 9, 2013 Share Posted January 9, 2013 FWIW, some characters have special purposes in the world of cookies and form-type data. The = character is a good illustration. It binds a name to a value. When it does that, it should not be encoded. Routines for extracting data look for the = and use it to parse the data. If the value of the data included an unencoded = character, those routines will attempt to parse a name-value pair that doesn't exist. So now your data is corrupted. That is why we encode the = character. There are similar explanations for other characters that get encoded. 1 Link to comment Share on other sites More sharing options...
James_Parsons Posted January 9, 2013 Author Share Posted January 9, 2013 thanks to both I was wondering what that was for Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now