clear all cookies js
- User
clear all cookies js
- Assistant
To clear all cookies using JavaScript, you can create a function that iterates through the document's cookies and removes each one. Here's a simple example of how to do this:
function clearAllCookies() { // Get all cookies in the document const cookies = document.cookie.split(";"); // Loop through each cookie and set its expiration date to a date in the past for (let cookie of cookies) { const cookieName = cookie.split("=")[0].trim(); // Set the cookie with the same name to an empty value and an expiration date in the past document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/;`; } } // Call the function to clear all cookies clearAllCookies();Explanation:
document.cookie.split(";"): This splits the cookies into an array based on the semicolon delimiter.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.