1

This is HTML & Javascript.

I have a variable that contains a div element of the page1. All I need is pass this variable to a page 2 (which gonna be embedded with iframe in page1, inside the div of that variable).

//So: (Javascript in page 1)

//This creates the div and gives it an id.
var MainDiv = document.getElementById('div');
MainDiv.id = "It's me!";

//And now, with JSON, "localStorage" it:
localStorage.setItem("MD", JSON.stringify(MainDiv));


//And now, in page2 we retrieve it, but the object is not the same
var Page1Div = localStorage.getItem("MD");
alert(Page1Div .id);
//This will output "undefined";

I make a try with jStorage too, (using):

$.jStorage.set("MD", MainDiv);
var Page1Div = $.jStorage.get("MD");

But still the same output of "undefied".

What I haven't understand, why this isn't capable to store the div object variable in localStorage?.

Reaversword
  • 169
  • 1
  • 4
  • 11

1 Answers1

1

It is not supported by default, but there is another possiblities. You can use this answer for an outerHTML. Then you can store this string to localStorage and restore it as a dom object by using jQuery.parseHTML after.

Community
  • 1
  • 1
Tony
  • 7,345
  • 3
  • 26
  • 34
  • Hmmm.. this appears gonna be impossible. I can't remake the div, because is that div where it is contained (with iframe) the page from where I need modify the attributes of the "father". Hmm, I'm gonna need change my strategy. Well.. thanks anyway, thanks for your time!. – Reaversword Jan 19 '14 at 16:46