zaolee_dragon
zaolee_dragon

Reputation: 109

How to pass a variable from one frame to another frame in HTML

Let's say I declared the variable var = 5; in frame1. Now how do I pass this variable to frame2? I'd like to pass it using a hyperlink. Are there any other ways to do that?

Also, how do I access that variable after passing to frame2 in frame2?

Upvotes: 0

Views: 1459

Answers (1)

Niles Tanner
Niles Tanner

Reputation: 4021

You could use a query string. You could set the link in JavaScript like this:

var a = document.getElementById('linkId');
a.href = "link?var=" + var;

You would have to run this code each time you change your variable.

If you need to parse the query string I would refer to this post: How can I get query string values in JavaScript?

Upvotes: 1

Related Questions