在不同浏览器中保留 JavaScript 变量值

huangapple go评论83阅读模式
英文:

Retain variable value in javascript in different browser

问题

在JavaScript中,是否可能在不同的浏览器中保留变量的值?我尝试过localStorage和sessionStorage,但它只在当前浏览器中有效。

我可以提供一个示例代码来实现这个吗?

谢谢。

英文:

Is it possible in javascript to retain the value of a variable not just in one browser but in a different browser? I tried localStorage and sessionStorage but it only works on the current browser only.

Can I have a sample code on how to achieve that?

Thank you.

答案1

得分: 1

一般来说,不可以。如果可能的话,这将构成巨大的安全风险。在您的情况下,数据应该保存在后端服务器或某种在线存储上。这是唯一的方法。

另外,请不要在stackoverflow上要求示例代码。SO更像是一个“知识数据库”,用于提出具体问题并寻找最佳解决方案,而不仅仅是提供“示例代码”。

英文:

Generally speaking, no - it cannot be done. If it were possible, it be a huge security risk. In your case, data should be saved on a backend server or some kind of online storage. That is the only way to do so.

Also, dont ask for sample code on stackoverflow. SO is more of a "knowledge database" - asking for specific problems and finding optimal solutions, rather than just providing "sample code".

huangapple
  • 本文由 发表于 2023年8月10日 13:53:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76872956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定