Skip to content

Instantly share code, notes, and snippets.

@jasonsanjose
Created July 28, 2014 20:49

Revisions

  1. jasonsanjose created this gist Jul 28, 2014.
    26 changes: 26 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    var cookieVal = document.cookie,
    testVal = "mixpanel",
    localStorageKey = "mixpanel-cookie",
    canWriteCookie = false;

    // Test cookie
    document.cookie = testVal;
    canWriteCookies = document.cookie === testVal;

    // Restore cookie
    document.cookie = cookieVal;

    if (!canWriteCookie) {
    Object.defineProperty(
    document,
    "cookie",
    {
    get: function () {
    return window.localStorage.getItem(localStorageKey);
    },
    set: function (val) {
    window.localStorage.setItem(localStorageKey, val);
    }
    }
    );
    }