JavaScript
  Home arrow JavaScript arrow Page 6 - 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: another way


    (Page 6 of 6 )

    The two previous sections demonstrated how to write content dynamically to an IFRAME.  But the example I showed you earlier may not be suited for real-world requirements.  Now, I would like to present you with another, better example, which could be really helpful!  Let us have a look at the following code.

    <html>
          <head>
                <meta  name=vs_targetSchema  content="http://schemas.microsoft.com/intellisense/ie5">
    <script  id="clientEventHandlersJS"  language="javascript">
    <!--
    function Show()
    {
          // get our iframe
            var testFrame = document.getElementById("myFrame");
                var val;
                val = "<TABLE border=1>";
                val += "<TR><TD>SlNo</TD><TD>Name</TD></TR>";
                val += "<TR><TD>1</TD><TD>Jag</TD></TR>";
                val += "<TR><TD>2</TD><TD>Chat</TD></TR>";
                val += "<TR><TD>3</TD><TD>Win</TD></TR>";
                val += "<TR><TD>4</TD><TD>Dhan</TD></TR>";
                val += "</TABLE>";
            // now write out the new contents
            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";
    }

    function Button1_onclick() {
    Show();
    }
    //-->
                </script>
          </head>
          <body>
          <iframe  id="myFrame"  frameborder="0"  vspace="0"  hspace="0"  marginwidth="0"
    marginheight="0"  width="100"  scrolling=yes height="100"
    style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; Z-INDEX: 999; LEFT: 20px; BORDER-LEFT: black 1px solid; BORDER-BOTTOM: black 1px solid; POSITION: absolute; TOP: 100px; visibility:hidden;"></iframe>

                <form  id="form1">
                      <input  type="button"  value="Show"  id="Button1"  name="Button1" onclick="return Button1_onclick()">
                </form>
          </body>
    </html>

    Within the above code, the only important issue is the following:

                var val;
                val = "<TABLE border=1>";
                val += "<TR><TD>SlNo</TD><TD>Name</TD></TR>";
                val += "<TR><TD>1</TD><TD>Jag</TD></TR>";
                val += "<TR><TD>2</TD><TD>Chat</TD></TR>";
                val += "<TR><TD>3</TD><TD>Win</TD></TR>";
                val += "<TR><TD>4</TD><TD>Dhan</TD></TR>";
                val += "</TABLE>";

    A new variable, “val,” is defined, which can contain any string (including any HTML).  You can observe that I concatenated some HTML script (which forms a TABLE) to the same variable.  Now, this variable is directly written to IFRAME, which makes you to see a dynamic TABLE in an IFRAME!

    Any comments, suggestions, ideas, improvements, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 1 Hosted by Hostway
    Stay green...Green IT