JavaScript代码
$cookies.put('test', 'test_value');
console.log('cookie value: ' + $cookies.get('test'));
我直接双击html文件以file:///C:/Users/xxxxx/test.html访问它,但我发现它无法写入或读取cookie:
cookie值:undefined
如果我将html文件放入' HTML' Nginx的文件夹并通过http://127.0.0.1/test.html访问它,我可以正常读取cookie:
cookie值:test_value
我不知道为什么,想知道解释。 THX。
答案 0 :(得分:0)
如果您通过file://加载页面,大多数浏览器都不允许您与Cookie进行交互,则需要从本地网络服务器提供页面。