Jump to content

open window object, then change pages. still same window?

Recommended Posts

Hi all,   I'm trying to wrap my head around the idea of the window object and the document object relationship.   I've read some really good explanations in stackoverflow and others.  I have a pretty good grasp of it so I tried an experiment.   If the window object opens in the browser, and then the document object opens in the window, then if I change the document, will the window object remain the same.  I tried make 2 simple html's - in the first I set a variable like  window.myVar = "myValue";.   I was able to change the value with a button so it was working fine, and then I used an <a> href to change to a different document.   I tried to reference the window.myVar but it came back 'undefined'.   If you change documents in a window, does the document always come with a new window, or am I doing something wrong here?   Like I said, I've read a lot about the window and document object, but I couldn't see that this was addressed.   Thank You for any response....

Link to post
Share on other sites

When you click on a link it opens a new page with an entirely new Javascript context, everything is lost unless it is saved in a cookie or storage. You can find information about storage here: https://developer.mozilla.org/en-US/docs/Web/API/Storage



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...