javascript - Global object not retrieved when stored in localStorage -



javascript - Global object not retrieved when stored in localStorage -

i trying store global object in localstorage on page1 runs around 4 seconds , redirects me new page eg: page2.

for storing global object in page1 localstorage use:

page1-- xyz.site.com/mycode.html

window.my_global_object = { property1: "abc", property2: "pqr" } window.localstorage["my_storage_vals"] = my_global_object;

page2: mylocal/page2.html

var retrievedobject = window.localstorage["my_storage_vals"]; alert(retrievedobject);

but still cannot see object beingness stored. it's still undefined. want maintain state of globalobject on page2 . not on page3 or page4 etc .. . want save values on page2.

using json.stringify

var val = json.stringify(my_global_object); localstorage.setitem("myval",val); var retrievedobject = localstorage.getitem("myval"); alert(retrievedobject);

you said pages are:

xyz.site.com/mycode.html mylocal/page2.html

the localstorage object bound local domain, xyz.site.com have totally different localstorage mylocal. hence, if set property in first page , redirect site, localstorage not same anymore, , you'll not have access property.

to work around should either:

put both pages on same domain or phone call sec page passing query string in url or implement xmlhttprequest sec first page.

javascript local-storage

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -