我有两个框架,我使用 JavaScript 将第一个 (myframe) 的内容复制到第二个 (myframe2) 并设置 myframe2 的来源:
<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>
FrameSecond 在设置“src”属性后重新加载,但我不需要它这样做。谁能帮我解决这个问题?
最佳答案
使用replaceState(state, title, URL)
:
iframe2.contentWindow.history.replaceState('WhatEverNameYouWant', "", iframe1.src);
关于javascript - 如何在不重新加载 iframe 的情况下更改 iframe src?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38408835/