使用另一个iframe镜像iframe页面(制作两个iframe)

时间:2019-05-24 10:19:43

标签: html css google-chrome iframe

我正在某个项目上,我需要一个只有这种设施的网页。通过使用html,我知道我们可以通过使用iframe在单个标签中使用多个标签,但是每个iframe的工作方式都不同。我需要的是,假设我在Chrome的单个标签中有两个iframe,因此,如果我在第一个iframe中打开网站,它也应该在另一个i框架中打开。 因此,在这里简单说明一个例子:假设我在这些框架中有5个iframe,而YouTube中有YouTube,因此我在一个框架中单击评论,但应在每个iframe中单击它。 当我在一个iframe YouTube评论框中输入“ hi”时,应在5个iframe YouTube评论框中分别输入“ hi”。当我点击发布时,应该同时在5个iframe中同时发布。 因此,我想使用iframe制作双页。 希望你们能理解我的问题。

1 个答案:

答案 0 :(得分:0)

我可以为您提供一些一般指导:

您无法从客户端上的JS访问元素,直接需要: 对于Vanilla Js使用.contentWindow.document或对于Jquery使用Contents()

Jquery W3school,例如 https://www.w3schools.com/jquery/traversing_contents.asp

在这里,我有2个iframe:重复了代码,但将其剪切以显示示例

您需要做的就是清理它,使其不再重复,然后传输值或进行更可靠的传输-例如遍历元素,传递参数

 <iframe id="myFrame" src="/your-iframe" style="your style"></iframe>


    <iframe id="myFrame2" src="/your-iframe" style="your style"></iframe>

    <button onclick="myFunction()">Try it</button>

    <script>
    function myFunction() {

/iframe 1
      var iframe = document.getElementById("myFrame");
           var elmnt1 = iframe.contentWindow.document.getElementsById("yourelement");
      elmnt1.style.display = "none";

/iframe 2
        var iframe = document.getElementById("myFrame2");
      var elmnt1 = iframe.contentWindow.document.getElementsById("yourelement");
      elmnt1.style.display = "none";

    }
    </script>

这只是说明了这个想法: 现在您围绕这个想法建立了客户端

相关问题