Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在iframe中动态包装文档?_Javascript_Jquery_Iframe - Fatal编程技术网

Javascript 如何在iframe中动态包装文档?

Javascript 如何在iframe中动态包装文档?,javascript,jquery,iframe,Javascript,Jquery,Iframe,我有一个不使用iFrame的网页。比如: <html> <head>...</head> <body >...(content)</body> </html> ... …(内容) 我想写一段代码,给出以下结果: <html> <head>...</head> <body > <iframe>...(content

我有一个不使用iFrame的网页。比如:

<html>
    <head>...</head>
    <body >...(content)</body>
</html>

...
…(内容)
我想写一段代码,给出以下结果:

<html>
    <head>...</head>
    <body >
        <iframe>...(content)</iframe>
    </body>
</html>

...
…(内容)
试试这个:

var iframe = document.createElement('iframe');
while (document.body.childNodes.length > 0) { 
    iframe.appendChild(document.body.childNodes[0]);
}
document.body.appendChild(iframe)

将第一个div包裹在身体内

e、 g HTML

<html>
<body>
<div class="inner">ALL contents</div>
</body>
 </html>

 **jquery**

$( ".inner" ).wrap( "<iframe></iframe>" );

全部内容
**jquery**
$(“.inner”).wrap(“”);

您尝试过什么吗?也许你做了什么(代码)?我做了第一个答案中提到的事情,但遇到了另一个问题。“内容”中似乎有一个iframe。当我用iframe包装“内容”时,这种情况就会消失。