Check if cookies are enabled

0 favourites
  • 5 posts
  • I tried to do a quick search, is there any fairly simple way of checking if cookies are enabled in a browser before starting our game? I had to debug a data saving feature for a game I am working on for about 2 hours last night until I realized I am a big dope and forgot to enable cookies for my local host

    <img src="smileys/smiley36.gif" border="0" align="middle" />

  • The best way is to check it before the game loads, with a java script like this.

    function are_cookies_enabled()

    {

         var cookieEnabled = (navigator.cookieEnabled) ? true : false;

         if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)

         {

              document.cookie="testcookie";

              cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;

         }

         return (cookieEnabled);

    }

    If you want the game to know if cookies are enabled, you can call this function trough AJAX and handle teh response.

  • fantastic, thank you for your help

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Or simpler and more C2 like use the condition "Cookies enabled" from the Browser plugin.

  • yeah he can do that, but if the game is large and it will not work with cookies disabled, my way will be faster and more effective.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)