Javascript Jquery获取iframe文档并设置另一个iframe
我正在尝试创建一些功能来获取和设置iframe的文档。我在使用jquery执行此操作方面一直不成功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
<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);