Cookie with multiple Name-Value pairsIn JavaScript, a cookie can contain only a single name-value pair. However, to store more than one name-value pair, we can use the following approach: -
Examples to Store Name-Value pair in a CookieExample 1Let's see an example to check whether a cookie contains more than one name-value pair. Output: Test it NowOn clicking Get Cookie button, the below dialog box appears. Here, we can see that only a single name-value is displayed. However, if you click, Get Cookie without filling the form, the below dialog box appears. Example 2Let's see an example to store different name-value pairs in a cookie using JSON. Test it NowOutput: On clicking Get Cookie button, the below dialog box appears. Here, we can see that all the stored name-value pairs are displayed. Example 3Let's see an example to store each name-value pair in a different cookie. Output: Test it NowOn clicking Get Cookie button, the below dialog box appears. Here, also we can see that all the stored name-value pairs are displayed. Next TopicDeleting Cookies |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India