6

I have a javascript variable called "myvar" in two different frames (frame1 and frame2). I need to take the myvar in frame1 and set it as the value of the myvar in frame2. How do I do this without an external script?

5
  • no, I'm just using framesets. Commented Feb 21, 2013 at 18:35
  • Save it to window.parent? Commented Feb 21, 2013 at 18:36
  • 2
    That having been said, you should probably be asking "why am I using framesets?"... It's 2013 man. Commented Feb 21, 2013 at 18:37
  • Working with cruddy computers that aren't exactly in the 21st century. Commented Feb 21, 2013 at 18:40
  • 1
    What do old PCs have to do with the use of old web technologies? Isn't that the whole reason? Harness the power of the server? Commented Feb 21, 2013 at 18:41

1 Answer 1

12

If the variable is in the parent, use:

window.parent.varName

If it's in another frame, go through the parent, then to the frame:

window.parent.frameName.varName
Sign up to request clarification or add additional context in comments.

5 Comments

How do you change the varName? could you use an example using "myvar" as both variables?
window.parent.frame1.myvar = window.parent.frame2.myvar
This only works for same scheme domains:port. As of same domain policy. Just to be curious.
are both frames on the same domain? sub domains on the same TLD?
Sorry, my bad. I needed to pass two variables. I only passed one. It's working now. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.