reading a variable out of an iframe parent

Subscribe to reading a variable out of an iframe parent 6 posts, 3 voices

 
dob Scriptwright

Hey there,

let's say I have this code:


<body>
<script>var foo = "bar";</script>
<frameset>
	<frame src="page.html" />
</frameset>
</body>

Inside page.html, I got a function which alerts the variable foo

It doesn't work, so I'm asking: Is there a way to read variables inside an iframe page which are embedded inside the page embedding my frame page?

Thanks!

 
The Dot Scriptwright

function() {
alert(top.foo);
}

 
sizzlemctwizzle Scriptwright

does this have anything to do with greasemonkey? also you could use top['foo'].

 
The Dot Scriptwright

im not sure of the original source of the question, but it could have to do with greasemonkey. on a page with frames, sometimes the script will be run on each window (or each frame). so in that case, it might be useful.

 
dob Scriptwright

It's not really about Greasemonkey, but I thought if I could find an answer to that, then here.

Thanks!

 
sizzlemctwizzle Scriptwright

@Dot
if (self.location == top.location) { //Make sure script doesn't preform in an iframe