我有两个并排的 iframe,只希望第一个加载 URL。第一个完成加载后,我希望第二个 iframe 具有相同的内容,而不加载相同的 URL。这是我尝试过的:
在这里测试:https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_script
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<script>
$(document).ready(function() {
$('#iframeID1').on('load', function() {
$('#iframeID2').contents().find('html').html($('#iframeID1').contents().find('html').html());
});
});
</script>
</head>
<body>
<iframe id="iframeID1" src="https://www.w3schools.com/" frameborder="0" scrolling="no" width="180px" height="512" align="left">
</iframe>
<iframe id="iframeID2" frameborder="0" scrolling="no" width="180px" height="512" align="middle">
</iframe>
</body>
</html>
但是,这是第二个 iframe(右侧)显示的内容(加载 CSS 失败?):
最佳答案
非 jquery 但你为什么不从页面读取 HTML,然后使用诸如...之类的东西动态创建第二个 iframe
Iframe.contentWindow.document.open('text/htmlreplace');
Iframe.contentWindow.document.write(htmlfromfirstiframe);
Iframe.contentWindow.document.close();
关于javascript - 如何在不加载相同 URL 的情况下镜像 iframe? CSS 未激活,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43835923/