SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ie appendChild problem.

    I have a 2 divs, one div has an iframe showing a pdf, i want to move the iframe from one div and place it in the other.

    the code is as follows

    <script>

    function swapSrc()
    {
    var div1 = document.getElementById("div1");
    var div2 = document.getElementById("div2");
    var if = document.getElementById("pdf1");
    div2.appendChild(if);
    div2.style.display = "block";
    div1.style.display = "none";
    }
    </script>

    </HEAD>

    <BODY>
    <div id="div2" style="border:3px solid red;margin-bottom:50px;display:none">
    </div>
    <div>
    <button name="swapSrc" onclick="swapSrc();">Swap</button>
    </div>
    <div id="div1" style="border:1px solid blue">
    <iframe id="pdf1" src="http://localhost/testPage/sample.pdf" style="height:250px;width:100%"/>
    </div>

    However once i do this the iframe does not get rendered in the new div. This works fine in firefox of course. If someone knows of a work around for this it would be much appreciated.

    Thanks

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Why exactly are you doing this? I think you should use cloneNode anyway. Clone pdf1 and then append it to div1. Then instead of setting div2's display to 'none', remove it entirely (unless you need it for something else) using removeChild.

    Also, next time you post code please use syntax highlighting (dropdown on top left of where you write your post).

  3. #3
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bigcodfish View Post
    var if = document.getElementById("pdf1");
    Try using the console - click on that yellow triangle in the bottom left corner, and don't disable it if you're going to write scripts.

    Perhaps not surprisingly, I.E. isn't expecting a keyword there.
    Tab-indentation is a crime against humanity.

  4. #4
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a very simple version of code i am using in a page where I have two divs representing a normal and a maximized window, when the user clicks the maximize button on the normal window we detach the markup in that div and attach it in the maximized div. I will give clone node a try and see how that works, thanks for the tip.

  5. #5
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about the confusion with the variable named if, thats not the name of the actual variable just something i entered when i was changing variable names in the post.


Bookmarks

Posting Permissions

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