如何在iframe中追加div元素

时间:2013-04-04 14:43:12

标签: html iframe

我有一个网站,我为了某种目的覆盖了一个div元素。现在我没有覆盖,而是想推送网页并将所有div放在iframe中。

我创建了iframe,但无法在iframe中添加div。

编辑:

var iframepush = document.createElement('iframe');
                        iframepush.frameBorder=0;
                        iframepush.scrolling="yes";
                        iframepush.id="crossrider-siderbar-iframepush-26337";
                        iframepush.allowTransperancy="true";
                        iframepush.style.position='fixed' 
                        iframepush.style.right = '0px';
                        iframepush.style.top = '0px';
                        iframepush.style.position = 'absolute';
                        iframepush.style.height = $(window).height() + 'px';
                        iframepush.style.width = '150px';
                        iframepush.style.display = 'inline-block';

                        document.body.appendChild(iframepush);

                        var rightDiv = iframepush.document.createElement("div");
                        rightDiv.className = "crossrider-sidebar-26337 crossrider-sidebar-26337-container ";
                        rightDiv.style.cssText = "display: block; position: fixed; right: 0px; top: 0px; width: 150px; height:" + $(window).height() + "px; z-index:970; ";
                        iframepush.document.body.appendChild(rightDiv);

1 个答案:

答案 0 :(得分:1)

  <script type="text/javascript">
    $(document).ready(function() {
      $("#iframeId").contents().find("body").html($("<div></div>").append($("#test")).html());
    });
 </script>
 <iframe id="iframeId" name="iframeId" src="about:blank" ></iframe>
<div id="test">
   Text
</div>