Jump to content

Javascript help


zkissane
 Share

Recommended Posts

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...