I am fairly new to JavaScript and I am trying to get value of a variable from an embedded iframe. I have resorted to basic testing to make sure I am getting the method right...
I have tried the common suggestions and everything returns 'undefined'. I want to use the variable in an onclick event.
In the iframe content I have stripped everything and just for testing have this:
<script> var test = "test"; </script> in the parent window I have done this:
<iframe src="iframe.html" id="iframe" width="200" height="100"></iframe> <script> var myVar = window.frames[0].window.test; </script> <a href="#" onclick='alert(myVar)' id="link">Click</a> I have tried the options suggested here: grab global variable from an embedded iframe
Everything I do returns undefined... am I doing something fundamentally wrong?
Thanks in advance..