使用javascript删除浏览器的所有Cookie [英] Delete all Cookies of browser using javascript

查看:647
本文介绍了使用javascript删除浏览器的所有Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此JavaScript代码,但它只返回特定页面的Cookie。我想清理浏览器的所有cookie

I am using this JavaScript Code, but it will return only cookies of a particular page. I want to clean all the cookies of Browser

function deleteAllCookies() {
    var cookies = document.cookie.split(";");
    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
};


推荐答案

您无法通过来自其他域的Javascript删除Cookie比你当前的页面。这是一个浏览器安全功能。并且,如果cookie被标记为特定路径,则只能从该特定路径上的页面访问它(即使是来自同一个域)。

You cannot delete cookies via Javascript that come from other domains than the page you are currently on. This is a browser security feature. And, if a cookie is marked for a particular path, you can only access it from a page on that particular path (even from the same domain).

并且,对于标记为 HttpOnly (例如服务器端只访问cookie),你甚至不能通过javascript删除你自己域名的那些。

And, for cookies that are marked HttpOnly (e.g. server-side access only cookies), you can't even delete those for your own domain via javascript.

清除所有cookie的唯一方法是您(用户)使用浏览器的用户界面删除cookie或将浏览器配置为在关闭浏览器时自动清除cookie。

The only way to clear all cookies is for you (the user) to use the browser's user interface to delete the cookies or to configure your browser to automatically clear cookies when you close the browser.

这篇关于使用javascript删除浏览器的所有Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆