Website Designers R Us - Home
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.
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 

<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. 

 

Return to Listing

Website Designers R Us is a professional Internet strategy and Web design company based in Toronto, Canada. We specialize in best-in-class website design, online marketing, Flash multimedia, corporate identity and print graphics. Website Designers R Us features an integrated team of web consultants, creative designers, writers, programmers and marketing professionals that know how to get online results
 Home          ::             About Us          ::             Support            ::             Services            ::             Link Partners          ::             Contact

Copyright © 2006-2007 Website Designers R Us, a DOT Specialist Company. All rights reserved.