1

JavaScript code

$cookies.put('test', 'test_value');
console.log('cookie value: ' + $cookies.get('test'));

I directly doubled click the html file to visit it by file:///C:/Users/xxxxx/test.html but I found it cannot write or read the cookie:

cookie value: undefined

If I put the html file into the 'HTML' folder of Nginx and visit it by http://127.0.0.1/test.html, I can read the cookie normally:

cookie value: test_value

I don't know why and want to know a explanation. Thx.

aka.ecc
  • 153
  • 3
  • 12

1 Answers1

0

If you load your page via file:// most browsers won't let you interact with cookies, you need to serve the page from a local webserver.

See this previous StackOverflow answer

Community
  • 1
  • 1
xeinherjar
  • 38
  • 4