DHTML
  Home arrow DHTML arrow Page 5 - Rough Guide To The DOM (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
DHTML

Rough Guide To The DOM (part 2)
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2001-05-09


    Table of Contents:
  • Rough Guide To The DOM (part 2)
  • Making The Swap()
  • Turning The Tables
  • Well-Formed
  • In The Frame
  • Branching Out
  • Dumbing It Down
  • Conclusions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Rough Guide To The DOM (part 2) - In The Frame
    ( Page 5 of 8 )

    It's also interesting to see how the DOM works with frames. Consider the following example, which sets up two frames, "left.html" and "right.html".

    <html> <head> </head> <frameset cols="20%,*"> <frame name="left" src="left.html" scrolling="auto" frameborder="no"> <frame name="right" src="right.html" scrolling="auto" frameborder="no"> </frameset> </html>

    In order to illustrate how to navigate across frames, I'm going to write a simple script which changes the background colour of the right frame when the appropriate link is clicked in the left frame. Here's the right frame

    <html> <head> </head> <body id="body"> </body> </html>

    and here's the left frame - note how each link calls the changeFrameBackground() function with a color as parameter.

    <html> <head> </head> <body> <a href="javascript:changeFrameBackground('red')">Red</a> <br> <a href="javascript:changeFrameBackground('blue')">Blue</a> <br> <a href="javascript:changeFrameBackground('green')">Green</a> <br> <a href="javascript:changeFrameBackground('black')">Black</a> </body> </html>

    Finally, let's take a look at the function which does all the work.

    <script language="JavaScript"> var bodyObj = top.right.document.getElementById("body"); function changeFrameBackground(col) { bodyObj.setAttribute("bgcolor", col); } </script>

    Since this is a frameset, it's necessary to prefix the document.getElementById() method call with a reference to the appropriate frame. This prefix is necessary to identify to the DOM which frame is being called, and to obtain a reference to the correct document tree.

    Once a reference to the right frame's <body> tag is obtained, changing the frame's background colour is a simple setAttribute() away.

    This article copyright Melonfire 2001. All rights reserved.

     
     
    >>> More DHTML Articles          >>> More By Vikram Vaswani, (c) Melonfire
     

       

    DHTML ARTICLES

    - Rough Guide To The DOM (part 2)
    - Rough Guide To The DOM (part 1)
    - Filters And Transitions In IE5
    - Understanding Embedded Fonts




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek