Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IFRAME CloneNode does not clone its contents?

    Hi,

    I really really need help in trying to figure out why CloneNode on an Iframe does not correctly clone the IFRAME with its contents and is there a workaround I can use to get pass this?. Basically what I am doing is dynamically building a table with Iframes inside it. The problem is I just want to build one Iframe because the contents of it can be very complex. After my Iframe is built I just want to clone the iframe as many times as I need later. I cannot use an HTML file and point the src of the Iframe to it. I have to put into the Iframe a very dynamic HTML document I get back form an Ajax call. This is truly the key of the problem. Since my pages can be complicated it can take around 2000ms to render. I don’t want to make each Iframe render every time when I already have the document ready to display. I just want to clone it very fast. I can not use the ‘scr’ of the iframe.


    Here is a very simple example of my problem. Look near the end of the code to see the problem. Try this code and you can see the IFRAME does not Clone its contents. Is there any way around this problem? Please note that I also cannot use innerHTML to populate the cloned Iframe with my master Iframe’s contents. Because if I do this the page still takes 2000ms to render. I just want this thing to clone as it is. Thanks in advance.

    <html>
    <head>
    </head>
    <body>
    <script language="JavaScript">

    function getIFrame(frameName)
    {
    for (var i=0; i<frames.length; i++)
    {
    if (frames[i].name == frameName)
    return frames[i];
    }
    return null;
    }

    // Create Table via DOM
    var TABLETAG = document.createElement('TABLE');
    TABLETAG.border = "1";

    // Create Table body tag
    var TBODYTAG=document.createElement('TBODY');
    TABLETAG.appendChild(TBODYTAG);

    // Create Table TR Tag
    var TRTAG = document.createElement('TR');
    TBODYTAG.appendChild(TRTAG);

    // Create Table TD Tag
    var TDTAG = document.createElement('TD');
    TRTAG.appendChild(TDTAG);

    // Append Table to Body
    window.document.body.appendChild(TABLETAG);

    // Create an Iframe
    var MyIFrame = document.createElement('<iframe name="MyIframe">');
    MyIFrame.setAttribute('width','100');
    MyIFrame.setAttribute('height','100');
    MyIFrame.setAttribute('src','about:blank');

    // Append IFRAME To TD
    TDTAG.appendChild(MyIFrame);

    // Get acces to Iframe now attached ot body so
    // I can add HTML code in it.
    var MyIFrame = getIFrame('MyIframe');
    MyIFrame.document.designMode='On';
    MyIFrame.document.open();
    MyIFrame.document.write("<div>f</div>");
    MyIFrame.document.close();
    MyIFrame.document.designMode='Off';

    //**************************************
    // ** Here is the problem. When the Table node
    // is Cloned the IFrame does not clone its contnents.
    // Help!!!!!***
    //*************************************
    TRTAG.appendChild(TDTAG.cloneNode(true));
    TRTAG.appendChild(TDTAG.cloneNode(true));
    TRTAG.appendChild(TDTAG.cloneNode(true));
    TRTAG.appendChild(TDTAG.cloneNode(true));

    </script>

    </body>
    </html>

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    The content of an element is the one in between its open and close tags including the sub-elements if any.
    As in:
    <textarea>content</textarea>

    In the case of Iframe, you want to clone the content of the file it is pointing to (src attribute) but technically, it has no content.

    <iframe src="page.htm"></iframe>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    The content of an element is the one in between its open and close tags including the sub-elements if any.
    As in:
    <textarea>content</textarea>

    In the case of Iframe, you want to clone the content of the file it is pointing to (src attribute) but technically, it has no content.

    <iframe src="page.htm"></iframe>
    ok, I am seeing the light but need more understanding of this. In my case the Iframe does not have a file to point to. If you look at my code you can see I am doing a IFRAME.Document.Write('<html><body>Test</body></html>'). I have the file in memory and I just put it into the iframe.So how do I get inside the iframe to clone the full <html> node stuck inside and trasnfer it to my cloned Iframe. Thats what i was trying to say when I noted 'content' . Also , why does the content or what ever is side the iframe not get cloned. I know its works if the src is set, but thats my problem, I can't use the src.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •