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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.