从webWorker访问localStorage [英] Accessing localStorage from a webWorker

查看:871
本文介绍了从webWorker访问localStorage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WebWorker可以访问localStorage吗?



如果不是,为什么不呢?从安全角度来看,它有问题吗?

解决方案

不,localStorage和sessionStorage在webworker流程中都未定义。 >

您必须将 postMessage()调回Worker的原始代码,并让该代码将数据存储在localStorage中。有趣的是,webworker can 可以使用AJAX调用向/从服务器发送/检索信息,这样可以打开可能性,具体取决于你正在尝试做什么。


Can a WebWorker access the localStorage?

If not why not? Is it problematic from a security stand point?

解决方案

No, localStorage and sessionStorage are both undefined in a webworker process.

You would have to call postMessage() back to the Worker's originating code, and have that code store the data in localStorage.

Interestingly, a webworker can use an AJAX call to send/retrieve info to/from a server, so that may open possibilities, depending on what you're trying to do.

这篇关于从webWorker访问localStorage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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