Javascript and Iframe Help

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Nov 2009
Posts: 1
Reputation: A___F is an unknown quantity at this point 
Solved Threads: 0
A___F A___F is offline Offline
Newbie Poster

Javascript and Iframe Help

 
0
  #1
31 Days Ago
Hi,

I'm a newbie and trying to use javascript to hide or display different divs within a single IFRAME. I can't seem to get the syntax right... the Iframe, ID "frame", has 5 div's which I want to show depending on what link someone clicks.

here's the js :

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2.  
  3. <!--
  4.  
  5. var iframe = document.getElementByID("frame");
  6. var info = iframe.contentDocument
  7.  
  8. function showFrame(page)={
  9. iframe.style.display="block";
  10. if (page = 'weak') {
  11. info.getElementByID("weak").style.display = "block";
  12. } else if (page = 'decap') {
  13. info.getElementByID("decap").style.display = "block";
  14. } else if (page = 'fire') {
  15. info.getElementByID("fire").style.display = "block";
  16. } else if (page = 'peppers') {
  17. info.getElementByID("peppers").style.display = "block";
  18. } else if (age = 'bottles') {
  19. info.getElementByID("bottles").style.display = "block";
  20. } else { iframe.style.display="hidden";}
  21. }
  22. //-->
  23. </script>

and here's the html

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <body>
  2. <div id="container">
  3. <div id="top">
  4. <img src="dhlogo.gif" id="logo"/>
  5. <img src="tagline.jpg" id="logo"/>
  6. </div>
  7.  
  8. <div id="decap">
  9. <a href="#" onclick="showFrame('weak')"><img src="weaksaucelogo.jpg" width="224" height="144" /></a>
  10. <a href="#" onclick="showFrame('decap')"><img src="decapsaicinlogo.jpg" /></a>
  11. <a href="#" onclick="showFrame('fire')"><img src="fireandice.jpg" /></a>
  12. <p>
  13. <a href="#" onclick="showFrame('peppers')"><img src="pepperinfo.jpg" /></a>
  14. <a href="#" onclick="showFrame('bottles')"><img src="bottleinfo.jpg" /></a>
  15.  
  16. <img src="shake.jpg" />
  17. </p>
  18.  
  19. <p><a href="mailto:decaphotsauce@gmail.com"><img src="email.jpg"></img></a></p></div>
  20.  
  21. <iframe width="400px" height="500px" scrolling="no" frameborder="0" src="frame.html" id="frame" name="frame" style="left:50%; margin-left: -200px; position:absolute; top:50%; margin-top:-250px; display: none;" ></iframe>
  22. </div>
  23. </body>

and here's frame.html :

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <body>
  2. <a href="javascipt:hideFrame()"><img src="bones2.gif" id="bones" style="border:none"/></a>
  3. <div id="info">
  4. <div name="weak" id="weak" style="display: hidden;"><img src="weakinfo.jpg" /></div>
  5. <div name="decap" id="decap" style="display: hidden;"><img src="decapsininfo.jpg" /></div>
  6. <div name="fire" id="fire" style="display: hidden;"><img src="fireinfo.jpg" /></div>
  7. <div name="peppers" id="peppers" style="display: hidden;"><img src="pepperinfotext.jpg" /></div>
  8. <div name="bottles" id="bottles" style="display: hidden;"><img src="recycle.jpg" /></div>
  9. </div>
  10. </body>

Perhaps there's a better way to approach this all together... as I said I'm a newb and any help would be greatly appreciated. Also, how do I close the iframe from within the iframe? I'm not sure that the javascript:Hideframe command is gonna work.

thanks again,

Andrew
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 37
Reputation: wonderland is an unknown quantity at this point 
Solved Threads: 0
wonderland wonderland is offline Offline
Light Poster
 
0
  #2
30 Days Ago
Hi,

I was looking for something like this a few days ago:

take a look at this: link

I hope this helps


By the way, as I searched net, more and more sites didn't recommend using Iframes altogether.
Last edited by wonderland; 30 Days Ago at 10:23 am.
Reply With Quote Quick reply to this message  
Reply

Tags
iframe, javascript

Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC