Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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 Jquery获取iframe文档并设置另一个iframe_Javascript_Jquery_Html_Iframe - Fatal编程技术网

Javascript Jquery获取iframe文档并设置另一个iframe

Javascript Jquery获取iframe文档并设置另一个iframe,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,我正在尝试创建一些功能来获取和设置iframe的文档。我在使用jquery执行此操作方面一直不成功 <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script></head> <body> <iframe sandbox="allow-same-origin allow-sc

我正在尝试创建一些功能来获取和设置iframe的文档。我在使用jquery执行此操作方面一直不成功

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script></head>
<body>
<iframe sandbox="allow-same-origin allow-scripts" id='a' height="700" width="700" src="http://localhost:8181/website"></iframe> 
<iframe sandbox="allow-same-origin allow-scripts" id='b' height="700" width="700" src="http://localhost:8181/website"></iframe> 
</body>
</html>
这将基本上将iframeb的内容设置为用户在iframea中导航的位置

有一个关于jquery和iframe的页面

如果iframe与主页位于同一域中,则可以使用.contents()方法获取iframe的内容文档

这应该起作用:

var theHtmlStringToSet = $('#frameA').contents().find('body').html();
$('#frameB').contents().find('body').html(theHtmlStringToSet);

你的问题不是很清楚。更具体一点,或者创建jsfiddle,并使用附加说明进行更新
var theHtmlStringToSet = $('#frameA').contents().find('body').html();
$('#frameB').contents().find('body').html(theHtmlStringToSet);