charles@stromme.ca Posted May 5, 2009 Share Posted May 5, 2009 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 More sharing options...
Ingolme Posted May 5, 2009 Share Posted May 5, 2009 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 More sharing options...
charles@stromme.ca Posted May 5, 2009 Author Share Posted May 5, 2009 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 More sharing options...
justsomeguy Posted May 5, 2009 Share Posted May 5, 2009 The correct property for an iframe is "src", not "location".http://www.w3schools.com/HTMLDOM/dom_obj_iframe.aspYou may also be able to use iframe.contentDocument.location.href instead of src. Link to comment Share on other sites More sharing options...
charles@stromme.ca Posted May 5, 2009 Author Share Posted May 5, 2009 The correct property for an iframe is "src", not "location".http://www.w3schools.com/HTMLDOM/dom_obj_iframe.aspYou may also be able to use iframe.contentDocument.location.href instead of src.And we have a winner. Thanks for your help. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.