如何读/写饼干的本地文件:/// HTML文档? [英] How to read/write cookies for local file:/// HTML document?

查看:169
本文介绍了如何读/写饼干的本地文件:/// HTML文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何读/写饼干的地方文件:/// HTML使用Javascript或jQuery的文档

How can I read/write cookies for local file:/// HTML document using Javascript or jQuery?

我想这一个>>

function setCookie(c_name, value, exdays)
{
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + exdays);
  var c_value = escape(value) + 
    ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
  document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name)
{
  var i, x, y, ARRcookies = document.cookie.split(";");
  for (i = 0; i < ARRcookies.length; i++)
  {
    x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
    y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
    x = x.replace(/^\s+|\s+$/g, "");
    if (x == c_name)
    {
      return unescape(y);
    }
  }
}

不过,这是行不通的。

But it does not work.

推荐答案

这要看你的浏览器。 Chrome浏览器如不允许使用cookie为本地文件。请参阅:在那里保存本地的HTML文件的cookie

It depends on your browser. Chrome e.g. doesn't allow cookies for local files. see: where cookie saved for local HTML file

这篇关于如何读/写饼干的本地文件:/// HTML文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆