Jump to content

[javascript] problem stocking/reading a cookie

so I go this piece of code 

 

<!DOCTYPE html>

<html>

<body>

<script>

 

document.cookie=("cookie=monster");

var x = document.cookie;

alert(x);

 

</script>

</body>

</html>

 

can somebody explain to me why this does not work as I've never done any cookie

Link to comment
Share on other sites

Link to post
Share on other sites

Are you using Chrome and opening the file by double clicking/right clicking instead of using an actual webserver?

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Are you using Chrome and opening the file by double clicking/right clicking instead of using an actual webserver?

yup

Link to comment
Share on other sites

Link to post
Share on other sites

yup

Chrome will only save cookies for "real" websites, it won't work if you're just opening a file. If you want to open files like that you can use FireFox or download a webserver to host the files from for Chrome.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Chrome will only save cookies for "real" websites, it won't work if you're just opening a file. If you want to open files like that you can use FireFox or download a webserver to host the files from for Chrome.

thx I'll use firefox then 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×