51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

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

英文:

Retain variable value in javascript in different browser

问题 {#heading}

在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}

得分: 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".


赞(3)
未经允许不得转载:工具盒子 » 在不同浏览器中保留 JavaScript 变量值