如何在不重新加载iframe的情况下更改iframe src? [英] How to change iframe src without reloading the iframe?

查看:174
本文介绍了如何在不重新加载iframe的情况下更改iframe src?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个框架,其中使用JavaScript将第一个( myframe )的内容复制到第二个( myframe2 )并设置 myframe2 的src:

I have two frames of which I copy the content of the first (myframe) to the second (myframe2) using JavaScript and set myframe2's 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>

设置"src"属性后,

FrameSecond 重新加载,但我不需要这样做.有人可以帮我吗?

FrameSecond reloads after "src" attribute is set, but I don't need it to do so. Can anyone help me with this?

推荐答案

使用 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆