Jump to content

Iframe Content Switch


charles@stromme.ca

Recommended Posts

I have written a javascript function that looks like this:

<script type="text/javascript">function switch_content(url){switch(url){case 'btn_page1'://change content of iFramebreak;case 'btn_page2'://change content of iFramebreak;case 'btn_page2'://change content of iFramebreak;}}</script>

I'm calling the function using an ExternalInterface call from a swf. What I'm not sure how to to is target the iFrame and replace the src. Any help would be appreciated. Thanks.

Link to comment
Share on other sites

To access a frame, you can use document.frames['framename'], or give the <iframe> an ID and call it using document.getElementById("frameid"). You can also access the iframe using document.getElementsByTagName("iframe")[0].Once you have targeted the frame you can change the location property. Such as the following example:

document.getElementById("myFrame").location = "http://www.google.com";

Link to comment
Share on other sites

Hey, thanks for the reply. I'm trying what you suggested, but it doesn't appear to be working. Here is the entire html page. The function is working, if i click button 3 the alert pops up.

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html xmlns="http://www.w3.org/1999/xhtml">	<head> 	<title>GroupGas</title>		<script type="text/javascript">		function switch_content(url){		switch(url){			case 'btn_page1':			document.getElementById("myFrame").location = "frame_a.html"			break;			case 'btn_page2':			document.getElementById("myFrame").location = "frame_b.html";			break;			case 'btn_page3':			alert(url)			document.getElementById("myFrame").location = "frame_c.html"			break;		}		}		</script>	</head>   	<body>	<center>		<object width="920" height="93">			<param name="allowScriptAccess" value="always" />			<param name="movie" value="movies/navigation_header.swf">			<embed src="movies/navigation_header.swf" width="920" height="93" allowScriptAccess="always" />			</object>	</center>	<center>		<object>		<iframe id=myFrame  src="frame_a.html" width=920 height=475 scrolling="no" frameborder="0" marginheight=0 marginwidth=0>				<p>Your browser does not support iframes.</p>		</iframe>			</object>	</center>	<center>		<object width="920" height="245">			<param name="allowScriptAccess" value="always" />			<param name="movie" value="movies/footer.swf">			<embed src="movies/footer.swf" width="920" height="245" allowScriptAccess="always"/>		</object>	</center>	</body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...