![]() |
Application Tab is a tool provided by Edge to view, edit, and delete cookies. Cookies are small files storing user-related information that is being stored by the web server using the client browser to make the website dynamic, i.e., the same site but different UI or functionality for different users. For example, if we visit a site and by default, it is in light mode, we change it to dark mode. The next time we visit the site, it presents itself in dark mode because the user theme choice is stored as a cookie. How to view cookie information:The Cookies pane is present in the Application Tab in developer tools. To open it follow these steps:
![]() Cookies Pane in Application Tab Understanding Various Options To Filter and Delete Cookies:Lets move from left to right to understand the various options provided to us. Options on top of the right section
Understanding Various Fields and Edit them:1. Fields of a Cookie:The complete information about the cookie is separated under various fields shown below: Various Fields of Cookies
2. Edit Fields of a Cookie:We can only edit Name, Value, Domain, Path, and Expires / Max-Age fields. To edit any field data we can just double click the field data and type our own data and then press Enter. ![]() Edited the Cookie Name and Value Handling Cookies with JavaScript:You can use JavaScript to read, create, update and delete cookies in your site. JavaScript uses the document object and cookie property to handle cookies. Let us understand one by one all operations done with the cookies using JS. All the code is executed using the HTML, CSS and JS IDE of GFG so, to test the code copy the below JS code under a script tag. 1. Create a Cookie:You can set the cookie using “document.cookie” property the values to be passed are name, value, expiry date and path. In the below code a myCookie() is called by passing the name, value and expiry days of the cookie. Its uses the date object to set the expiry date of the cookie in UTC. Javascript
Output: My custom created Cookie 2. Read a Cookie:You can use “document.cookie” property to get all the cookies and there value. It will return all cookies with there values separated by ‘;’ in the format cookieName=value; . Use the below code to get all cookies at once. Javascript
Output: ![]() All cookies of GFG You can also get the cookie with respect to a given name. We create a readCookie() which takes a name parameter. The “document.cookie” property returns all the cookies name with value so, to get a particular cookie we first split the cookies into an array of string of cookieName=value. The function then removes any initial space in the strings and then check for the name of the cookie if its matched then it returns the value of the cookie. Javascript
Output: Reading Cookie named gfg_theme 3. Update a Cookie:You can edit a cookies name, value, path and expiry days using the document.cookie property. Just have the updated value in sting and pass it into document.cookie property. Javascript
Output: Updating GFG cookie 4. Delete a Cookie:You can delete the cookie by setting the expires parameter to a past date. The function below just take the cookie name to be deleted and set the cookie name to a empty value and sets the expiry time to be some past date. Javascript
Output: You can see GFG cookie is not present in the image below. Deleted GFG cookie ConclusionCookies are a way for website to identify the user and provide features and UI changes targeting that user. Edge allows us tools to monitor and modify these cookies. You can check all the cookies information in a tabular manner. Edge browser can be used during development when we create, update, delete or read a cookie to monitor and debug these cookies. |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |