Skip to main content

clearCookie 🚨

clearCookie 清除 cookie

注意: HttpOnly 不允许脚本访问, 客户端无法操作. 因此不推荐使用.

🍱 参数

  1. [string] name: cookie 名称, 不传则清除所有 cookie

🔥 返回值

🚀 示例

import { clearCookie } from 'atools-js';

clearCookie(); // 清除所有 cookie

💡 源码

source code
/atools/_browser/clearCookie.ts
export const clearCookie = () => {
// Environmental Test
if (!isBrowser)
throw new Error("Non-browser environment, unavailable 'cleanCookies'");

if (!document.cookie) throw new Error('No Cookie Found');

for (let i = 0; i < getCookie().length; i++) {
const element = getCookie()[i];
document.cookie = element
.replace(/^ +/, '')
.replace(element.match(/=(\S*)/)[1], ``);
}
};