HTML
  Home arrow HTML arrow Page 2 - The power of DIV with IFRAME
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
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? 
HTML

The power of DIV with IFRAME
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2006-03-08

    Table of Contents:
  • The power of DIV with IFRAME
  • Using a DIV as variable to write into IFRAME: discussion
  • Making DIV more dynamic to write into IFRAME
  • Creating your own library to write dynamic content to IFRAME: essentials
  • Creating your own library to write dynamic content to IFRAME: utility functions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    The power of DIV with IFRAME - Using a DIV as variable to write into IFRAME: discussion


    (Page 2 of 5 )

    Looking at the code from the previous section, the first important issue to consider is the following:

    <div  id="dvSample">
          <!--
            <html>
              <body>
                Hai, this is from Div!
              </body>
             </html>
           -->
    </div>

    That is simply a DIV containing some information (inside the comments) which is needed to send to IFRAME dynamically.

    Within the code in the previous section, I mainly created a simple button (which is identified as “Button1”).  The button is defined with an “onclick” event which calls a JavaScript function, “Button1_onclick.”  The same function simply calls another JavaScript function named “Show.”

    Let me explain the function “Show” part by part.  Let us consider the following first:

          var tDiv = document.getElementById("dvSample");

    The above statement tries to find the DIV tag in our document (which is specified earlier).  The handle of the DIV tag is stored in “tDiv.”

            var FirstElement = tDiv.firstChild;
            var v = FirstElement.nodeValue;

    The first statement tries to find the first element within the DIV (which is nothing but the comment).  The second statement mainly retrieves the whole content available within the comment (which is nothing but the entire HTML available).

            var tFrame = document.getElementById("myFrame");

    The above statement tries to retrieve the handle of the IFRAME, which is declared in our web page with the ID “myFrame.”  Proceeding further, we have the following:

            var doc = tFrame.contentDocument;
            if (doc == undefined || doc == null)
                doc = tFrame.contentWindow.document;

    To write some content to the IFRAME, we need to get the handle of the “document” object of the specific IFRAME.  This is achieved through the above statements.  The “if” statement is a simple “hack” to make it work with different browsers.  Continuing, we have the following:

            doc.open();
            doc.write(v);
            doc.close();

    Once we get the handle of the “document” object of the respective IFRAME, we need to open it, write the content and close it.  The three above do the same.  The content which needs to be written into the IFRAME is stored within the variable “v” (at the beginning).

    Not only can we use simple information, but we can also embed any HTML into DIV when necessary.  You can replace the above DIV with the following and test it once again:

    <div  id="dvSample">
          <!--
            <html>
              <body>
                <h1>heading</h1><hr>
                Hai, this is content!
              </body>
             </html>
           -->
    </div>

    More HTML Articles
    More By Jagadish Chaterjee


       · Hello guys! A fine introduction on using DIV with IFRAME. enjoy and give any...
       · I tried this tutorial but it didn't work in firefox. what are the firefox work...
       · I tried this tutorial but it didn't work in firefox 3.0. what are the firefox work...
     

    HTML ARTICLES

    - Completing Construction of a Database Form w...
    - Maximizing and Restoring Images in a Tabular...
    - Building the Recordset for an HTML Database ...
    - Laying Out a Database Form with HTML
    - Tabular Database Form Functions with HTML
    - Tabular Database Forms with HTML
    - Using the Find Functions for HTML Database F...
    - Sorting for Database Forms with HTML
    - Edit and Other Database Form Functions with ...
    - More Database Form Functions with HTML
    - Database Form Functions with HTML
    - Using the HTML Table Element as a Recordset
    - Building Single Row Database Forms with HTML
    - Introduction to Database Forms with HTML
    - Another Look at Animation of Geographical Ma...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT