![]() |
Get best price on Unlocked International Phone w/Triple Cameras |
![]() |
||||||||||
![]() |
||||||||||||
|
||||||||||||
![]() |
![]() |
|
![]() |
![]() |
JavaScript: How to Work With Cookies (Part 3)Retrieving a Cookie
The code to retrieve a cookie is a little more complicated, because you
have to scroll through all cookies to find yours. Here is the JavaScript getCookie function:
<script language="JavaScript">
function getCookie (name) { var dc = document.cookie; var cname = name + "="; if (dc.length > 0) { begin = dc.indexOf(cname); if (begin != -1) { begin += cname.length; end = dc.indexOf(";" begin); if (end == -1) end = dc.length; return unescape(dc.substring(begin, end)); } } return null; } </script> Lets retrieve the cookie we just set and display the value in a text box: The HTML to retrieve the value of myCookie (the cookie we just set) is:
<form>
<input type="button" value="Get Cookie Value" onClick="this.form.tf.value = getCookie('myCookie')"> <input type="text" name="tf" size="30"> </form> Special thanks to Brig at IntoText.com for pointing out and offering a fix for my typo in the getCookie function above.
Related Links:
Cookie Central -- a site devoted completely to information about cookies.
|
![]() |
![]() |
![]() |
privacy policy || © 1997-2016. astonishinc.com All Rights Reserved. |