我有两个框架,我使用 JavaScript将第一个 ( myframe )的内容复制到第二个 ( myframe2 ) 并设置myframe2的 src:
<iframe id="myframe" src="../Page1.aspx" width="100%" height="100px"></iframe>
<iframe id="myframe2" width="100%" height="100px"></iframe>
<button onclick="myFunction();return false;">Try it</button>
<script>
function myFunction() {
var iframe1 = document.getElementById("myframe");
var iframe2 = document.getElementById("myframe2");
iframe2.contentWindow.document.body.parentElement.innerHTML = iframe1.contentWindow.document.body.parentElement.innerHTML;
iframe2.setAttribute("src", iframe1.src);
}
</script>
Run Code Online (Sandbox Code Playgroud)
FrameSecond在“src”属性设置后重新加载,但我不需要它这样做。谁能帮我这个?