如何将javascript对象从一个页面发送到另一个页面? [英] How to send javascript object from one page to another page?

查看:82
本文介绍了如何将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);

这篇关于如何将javascript对象从一个页面发送到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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