使用 javascript 将图像读/写到 IndexedDB
我需要帮助为 Web 应用程序编写 javascript(jquery?),以将一组图像保存到 IndexedDB,然后将它们加载到 html 页面中。
我有两个 html 页面,img.html 只是这种格式的图像列表:
'image-id','base64-image'
和 index.html,我的主页,包含一系列这种格式的图像标签:
<img name="imglist" id="image-id" img-src="">
我希望用户能够单击一个按钮将所有图像从 img.html 加载到 IndexedDB 中,然后单击另一个按钮从 IndexedDB 读取图像并将它们插入到 index.html 中适当的图像标签中(img.html 中的“image-id”对应于适当的img标签id索引.html)。
另外,是否可以设置一个cookie(或其他方法)来导致数据库在一段时间后被删除?我希望能够强制用户每周从服务器重新加载图像一次。
我不太擅长 javascript 或 indexeddb,所以任何帮助或示例都会很棒。
I need help writing javascript (jquery?) for a web app to save a set of images to an IndexedDB and then load them into an html page.
I have two html pages, img.html that is just a listing of images in this format:
'image-id','base64-image'
and index.html, my main page that includes a series of image tags in this format:
<img name="imglist" id="image-id" img-src="">
I'd like the user to be able to click a button to load all of the images from img.html into IndexedDB and then click another button to read the images from IndexedDB and insert them into the appropriate image tag in index.html (the 'image-id' in img.html corresponds to the appropriate img tag id in index.html).
Also, is it possible to set a cookie (or some other method) that will cause the DB to be erased after a certain time period? I'd like to be able to force the user to re-load the images from the server about once a week.
I'm not great with javascript or indexeddb, so any help or examples would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅标题为 在 IndexedDB 中存储图像和文件的文章< /a>.
注意我刚刚在这里发布了类似的问题,尽管它涉及跨站点请求的特殊情况。如果您的请求位于同一站点,则上面的链接应该是您工作的完美示例。
See the article titled Storing images and files in IndexedDB.
N.B. I just posted a similar question here, though it concerns the particular case of a cross-site request. If your requests are on the same site, the link above should be a perfect example for you to work by.