admin管理员组文章数量:1314574
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";
}
};
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";
}
};
Share
Improve this question
asked Mar 2, 2015 at 7:24
Satish SomaniSatish Somani
651 gold badge2 silver badges7 bronze badges
7
- 1 look at this stackoverflow./questions/595228/… – Arunprasanth K V Commented Mar 2, 2015 at 7:25
- i already use that but its also returning same – Satish Somani Commented Mar 2, 2015 at 7:27
- You can only remove cookies created by JavaScript - if a cookie was create by the server, then you cannot remove it through JavaScript.you need to know name, path and domain of a cookie then only you can reliably delete the cookie – Arunprasanth K V Commented Mar 2, 2015 at 7:27
- I want to clean the cookies that is created by facebook and our web application. what is path here.. Domain is facebook. name is name of cookie – Satish Somani Commented Mar 2, 2015 at 7:29
- I think what you are trying to do is accessing cross domain cookie.Which is not possible due to security reason. How ever I will look forward to see the answer of this. – Abhisek Malakar Commented Mar 2, 2015 at 7:37
1 Answer
Reset to default 4You cannot delete cookies via Javascript that e 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).
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.
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.
本文标签: Delete all Cookies of browser using javascriptStack Overflow
版权声明:本文标题:Delete all Cookies of browser using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741964433a2407465.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论