JavaScript
  Home arrow JavaScript arrow Page 5 - Working with IFRAME in JavaScript
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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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? 
JAVASCRIPT

Working with IFRAME in JavaScript
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 126
    2006-03-01

    Table of Contents:
  • Working with IFRAME in JavaScript
  • How to open a dynamic page in IFRAME using JavaScript
  • How to open a dynamic page in IFRAME using JavaScript: discussion
  • How to write content dynamically into IFRAME using JavaScript
  • How to write content dynamically into IFRAME using JavaScript: discussion
  • How to write content dynamically into IFRAME using JavaScript: another way

  • 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


    Working with IFRAME in JavaScript - How to write content dynamically into IFRAME using JavaScript: discussion


    (Page 5 of 6 )

    Within the code in the previous section, I mainly created a simple text box and a button.  The textbox is named “txtContent” and the button is named  “ButtonShowMsg.”  The button is defined with an “onclick” event which calls a JavaScript function “ButtonShowMsg_onclick,” which is defined as follows:

    function ButtonShowMsg_onclick() {
    var v = document.all("txtContent").value;
    Show(v);
    }

    The above function defines a variable “v”, which is assigned with a value available (or typed) in the textbox “txtContent.”  The same variable is passed as a parameter to another JavaScript function, “Show.” 

    The function “Show” is defined as follows:

    function Show(val)
    {
            var testFrame = document.getElementById("myFrame");
            var doc = testFrame.contentDocument;
            if (doc == undefined || doc == null)
                doc = testFrame.contentWindow.document;
            doc.open();
            doc.write(val);
            doc.close();
        
          document.all.myFrame.style.visibility="visible";
    }

    Let me explain the above function part by part.  Let us first consider the following statement.

            var testFrame = 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.”  Further proceeding we have the following:

            var doc = testFrame.contentDocument;
            if (doc == undefined || doc == null)
                doc = testFrame.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.  Further proceeding, we have the following:

            doc.open();
            doc.write(val);
            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.  All three above do the same.

    More JavaScript Articles
    More By Jagadish Chaterjee


       · Hai, want to work with IFRAME? here is a simple article on that. any doubts you...
       · Hello ,I am Riddhi Bhavsar.I am a Web Developer.And I am a beginner for...
       · how can i write content to the iframe if it has an src valuelike <iframe...
       · Is it possible to use iFrame to read a simple text file? I have some code for...
     

    JAVASCRIPT ARTICLES

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







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