Home arrow HTML arrow The power of DIV with IFRAME
HTML

The power of DIV with IFRAME


This article mainly explains the benefits of using DIV to write dynamic content to IFRAME. I shall also guide you in developing your own library of functions to work with IFRAME effectively.

Author Info:
By: Jagadish Chaterjee
Rating: 4 stars4 stars4 stars4 stars4 stars / 78
March 08, 2006
TABLE OF CONTENTS:
  1. · The power of DIV with IFRAME
  2. · Using a DIV as variable to write into IFRAME: discussion
  3. · Making DIV more dynamic to write into IFRAME
  4. · Creating your own library to write dynamic content to IFRAME: essentials
  5. · Creating your own library to write dynamic content to IFRAME: utility functions

print this article
SEARCH DEVARTICLES

The power of DIV with IFRAME
(Page 1 of 5 )

All of the examples in this article (except for the ones in the last two sections) can be directly tested by simply copying and pasting all of the code in each section into any text file, saving it with the extension .HTM, and opening it using a browser.

Using a DIV as variable to write into IFRAME

I already introduced you to writing dynamic content with IFRAME using JavaScript in last week's article.  I strongly suggest you refer to the previous article, if you are new at using JavaScript with IFRAME.

In this article, we shall focus on using DIV as a template of information to write to IFRAME.  To be frank, I got this technique from one of my friend and I really want to share the same with all of you.  I must congratulate him for coming up with such an innovative idea.

Now, let us try to develop a simple script (JavaScript) which shows the technique of using DIV with IFRAME. The entire code for the sample is as follows:

<html>
      <head>
            <meta  name=vs_targetSchema  content="http://schemas.microsoft.com/intellisense/ie5">
<script  id="clientEventHandlersJS"  language="javascript">
<!--
function Show()
{
      var tDiv = document.getElementById("dvSample");
        var FirstElement = tDiv.firstChild;
        var v = FirstElement.nodeValue;
        var tFrame = document.getElementById("myFrame");
        var doc = tFrame.contentDocument;
        if (doc == undefined || doc == null)
            doc = tFrame.contentWindow.document;
        doc.open();
        doc.write(v);
        doc.close();
      document.all.myFrame.style.visibility="visible";
}

function Button1_onclick() {
Show();
}
//-->
            </script>
      </head>
<body>
<div  id="dvSample">
      <!--
        <html>
          <body>
            Hai, this is from Div!
          </body>
         </html>
       -->
    </div>
      <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>

Actually, within the above code, the “meta” tag is not necessary.  Since I developed the above code using Visual Studio.NET 2003 Enterprise Architect, it was automatically added to provide its full-featured mechanisms. 

The explanation for the above code is given in the next section.


blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials