Check if cookies are enabled

Get help using Construct 2

Post » Wed Sep 12, 2012 5:42 pm

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


B
8
S
1
Posts: 61
Reputation: 1,210

Post » Wed Sep 12, 2012 7:54 pm

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.
B
15
S
3
G
2
Posts: 42
Reputation: 2,412

Post » Wed Sep 12, 2012 8:10 pm

fantastic, thank you for your help
B
8
S
1
Posts: 61
Reputation: 1,210

Post » Wed Sep 12, 2012 8:22 pm

Or simpler and more C2 like use the condition "Cookies enabled" from the Browser plugin.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Wed Sep 12, 2012 8:30 pm

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.
B
15
S
3
G
2
Posts: 42
Reputation: 2,412


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests