huggi / src /lib /utils /cookiesAreEnabled.ts
nsarrazin's picture
nsarrazin HF staff
Open in new tab if cookies are disabled (#580)
bb33d30 unverified
raw
history blame
403 Bytes
import { browser } from "$app/environment";
export function cookiesAreEnabled(): boolean {
if (!browser) return false;
if (navigator.cookieEnabled) return navigator.cookieEnabled;
// Create cookie
document.cookie = "cookietest=1";
const ret = document.cookie.indexOf("cookietest=") != -1;
// Delete cookie
document.cookie = "cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
return ret;
}