文件协议下的Javascript / HTML存储选项(file://) [英] Javascript/HTML Storage Options Under File Protocol (file://)

查看:137
本文介绍了文件协议下的Javascript / HTML存储选项(file://)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个html应用程序,它基本上就像一本书一样的一系列页面。在这个应用程序中,我想跨页面存储几个JavaScript变量。认为像阅读页面,书签等东西。当通过HTTP查看这个应用程序时,我打算使用localStorage和旧版浏览器的回退(globalStorage,userData等)。



<但是,如果文件是通过file://访问的,例如从CD中查看文件,则会彻底崩溃。似乎大多数(如果不是全部的话)localStorage解决方案在文件协议下不起作用。 Cookie不是file://下的选项。



有关如何通过html页面查看跨页面JavaScript数据的任何想法, file://?



它只需要在当前用户会话中可用。我真的不想使用框架,但到目前为止,我无法想到另一种方法来完成这个功能。

解决方案

我的工作伙伴通过分享他使用window.name的实现来在单个窗口/会话的页面之间存储数据,帮助我解决了这个问题。



A类似的实现(以及围绕该方法的讨论)可以在这里找到: http://ajaxian.com / archives / whats-in-a-windowname



我对这种方法进行的初步测试看起来非常有前途。我在以下浏览器的文件协议(来自桌面,a.k.a. - file:\的加载页面)下对此进行了测试。它对所有人都有效!!




  • IE 6

  • IE 7

  • IE 8

  • IE 9

  • FF 3.6

  • FF 4

  • Chrome 11

  • Opera 10

  • Safari 4



我还没有做过任何测试,可以在这里存储多少数据,但互联网似乎同意2 MB的值。



消息来源,链接,更多信息


I am developing an html application that is essentially a series of pages like a book. Within this application, I would like to store several JavaScript variables across pages. Think things like pages read, bookmarks, etc. When this application is viewed over HTTP, I plan to use localStorage with fallbacks for older browsers (globalStorage, userData, etc.).

However, this completely breaks down if the files are accessed via "file://", for example if viewed off of a CD. It seems that most (if not all) localStorage solutions will not work under the file protocol. Cookies are not an option either under "file://".

Any ideas on how to persist JavaScript data across html pages when they are being viewed via "file://"?

It really only needs to be available in the current user session. I really don't want to use frames, but as of yet, I can't think of another way to accomplish this

解决方案

A buddy of mine at work helped me out with this problem by sharing his implementation of using window.name to store data across pages of a single window/session.

A similar implementation (and discussion around the method) can be found here: http://ajaxian.com/archives/whats-in-a-windowname

Preliminary tests I've been doing on this method look very promising. I tested this, under the file protocol (loading page from desktop, a.k.a. - "file:\") on the following browsers. It worked on all of them!!

  • IE 6
  • IE 7
  • IE 8
  • IE 9
  • FF 3.6
  • FF 4
  • Chrome 11
  • Opera 10
  • Safari 4

I have not yet done any testing as to how much data you can store here, but the internets seem to agree on a value of 2 MB.

Sources, links, more information

这篇关于文件协议下的Javascript / HTML存储选项(file://)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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