Girish
Girish

Reputation: 107

How to send javascript object from one page to another page?

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.

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.

Upvotes: 1

Views: 5434

Answers (2)

user2521439
user2521439

Reputation: 1425

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.

E.g:

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);

Upvotes: 4

gulshanm01
gulshanm01

Reputation: 195

you can use localStorage.setItem(key,value) and fetch the value on another page using localStorage.getItem(key)

Upvotes: 2

Related Questions