
在开发基于微信的Web页面时,发现有些机型不能存储信息到localStorage中,或者是页面一旦关闭,存储的信息也失效了。
用cookie来替代localStorage,存储一些简单的数据。上网查找了一下,发现w3school上已有不错的解决方案。
设置cookie:
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate() expiredays)
document.cookie=c_name “=” escape(value)
((expiredays==null) ? “” : “;expires=” exdate.toGMTString())
}
//取回cookie
function getCookie(c_name)
{
if (document.cookie.length
© 版权声明
文章版权归作者所有,未经允许请勿转载。
相关文章
暂无评论...