How to make an iFrame to go fullscreen on a button click?(如何使 iFrame 在单击按钮时全屏显示?)
问题描述
我想让 iFrame 使用 JavaScript 单击按钮以全屏显示.
I would to make the iFrame to appear on fullscreen with a button click using 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>
推荐答案
你必须做两件事:让窗口全屏,然后 <iframe>
填满整个大小.
You will have to do two things: make the window fullscreen, and then the <iframe>
to fill up the whole size.
您可以使用 JS 使其全屏显示,例如 this SO answer.
You can make it go fullscreen with JS such as in this SO answer.
然后,要使其全尺寸,只需添加一些样式,如下所示.这个 JS 脚本所做的是将具有这些样式的类添加到 <iframe>
.
Then, to make it full size, just add a few styles, like below. What this JS script does is add a class with those styles to the <iframe>
.
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 上的这个部分工作*示例.
See this partially working* example on JSFiddle.
*部分工作,因为 JSFiddle 不允许全屏方法,因为它认为它不安全.但它应该适合你.
这篇关于如何使 iFrame 在单击按钮时全屏显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使 iFrame 在单击按钮时全屏显示?


基础教程推荐
- Chart.js 在线性图表上拖动点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01