zkissane Posted November 7, 2006 Posted November 7, 2006 I have an iframe. Here is its source, zak_iframe.htm : <html> <head> <script type="text/javascript"> var my_var = 42; var another_var = my_var; </script> </head> <body> <p>Hello, world! <br/> <script type="text/javascript"> document.write("My value is " + my_var + " "); document.write("another_var value is " + another_var); </script> </p> </body> </html> Here is its parent, zak_outer_frame.htm : <html> <head> <script type="text/javascript"> function print_value() { try { document.write("Inside javascript in main page <br/>"); var target_value = //???---This is what I don't know---???// document.write("My iframes value is " + target_value); } catch(err) { txt="Error description: " + err + "nn" alert(txt) } } </script> </head> <body> <p> <iframe src="zak_iframe.htm" title="zak" name="zak" id="zak"> </iframe> </p> <p> <br/> <script type="text/javascript"> print_value(); </script> </p> </body> </html> I want to set target_value (which lives in the parent) to my_var (which lives in the iframe). I've tried many different ways. Sometimes the output is blank, sometimes the output is "My iframes value is undefined " and sometimes the output is "My iframes value is null" depending on what I've tried. I've tried: var target_value = frames['zak'].document.my_var; var target_value = frames["zak"].document.getElementById("my_var") var target_value = frames["zak"].window['my_var'] all with no success. What am I doing wrong? Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now