如何将javascript对象从一个页面发送到另一个页面?

如何将javascript对象从一个页面发送到另一个页面?

问题描述:

假设我有一个名为call的javascript对象,我已经在其中存储了一些值,我想访问同一个对象call而不是值。这种方法有可能吗?

Assume i have javascript object called "call" and i have stored some values in it and i want to access the same object "call" not values. This type of approach is it possible?

如果是,请用简单的例子解释。

If yes plese explain with simple example.

我知道有几种方法可以发送对象属性通过使用post url,header,cookies等从一个页面到另一个页面的值,但我需要访问整个对象instanse从一个页面到另一个页面。

I know there are several ways we can send the object properties values from one page to another page by using post url, header, cookies so on but my requirment to access the whole object instanse form one page to another page.

任何内容对此表示高度赞赏。在此先感谢。

Anything in this regard highly appreciated. Thanks in advance.

除了@ gulshanm01存储和检索对象的答案之外,您还可以使用 JSON.parse() JSON.stringify()来解析存储的对象。

Just in addition to @gulshanm01's answer to store and retrieve an object you can use JSON.parse() and JSON.stringify() to parse the stored object.

例如:

var obj = {
    fruit: "banana",
    fruit2: "apple",
    fruit3: "orange"
};
//Store
localStorage.setItem("obj", JSON.stringify(obj));
//Then retrieve
var localObj = JSON.parse(localStorage.getItem(obj));
alert(localObj.fruit);