【问题标题】:How to make an iFrame to go fullscreen on a button click?如何使 iFrame 在单击按钮时全屏显示?
【发布时间】:2016-02-19 12:10:04
【问题描述】:

我想让 iFrame 使用 JavaScript 单击按钮以全屏显示。

<iframe id="iframe_view" class="embed-responsive-item container well well-small span6" style="height: 720px; width: 1280px; background-color: #2e2e2e;" src="https://www.google.com/" frameborder="0" scrolling="no" allowfullscreen>

【问题讨论】:

    标签: javascript iframe onclick fullscreen


    【解决方案1】:

    您必须做两件事:将窗口设为全屏,然后将 &lt;iframe&gt; 填满整个大小。

    您可以使用 JS 使其全屏显示,例如 this SO answer

    然后,要使其全尺寸,只需添加一些样式,如下所示。这个 JS 脚本所做的是将具有这些样式的类添加到 &lt;iframe&gt;

    JS

    document.getElementsByTagName("iframe")[0].className = "fullScreen";
    

    CSS

    body, html {
        height: 100%;
        margin: 0;
    }
    .fullScreen {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
    }
    

    请参阅 JSFiddle 上的 this partially working* example

    *部分工作,因为 JSFiddle 不允许全屏方法,因为它认为它不安全。但它应该适合你。

    【讨论】:

    • 感谢您的示例和答案。很有帮助!
    • @ssk 我很高兴能帮上忙!
    • 这是一个副本:cmsdk.com/css3/…
    • @Theodore 你倒退了。这篇文章是两年前的。
    • 啊,所以他们偷了你的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 2020-07-21
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    相关资源
    最近更新 更多