943,962 Members | Top Members by Rank

Ad:
Nov 5th, 2009
0

Javascript and Iframe Help

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
A___F is offline Offline
1 posts
since Nov 2009
Nov 5th, 2009
0
Re: Javascript and Iframe Help
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; Nov 5th, 2009 at 10:23 am.
Reputation Points: 10
Solved Threads: 0
Junior Poster
wonderland is offline Offline
108 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Get, show PDF, JPG, Video
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: RSS reader needed





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC