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="aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbS8=" 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 在单击按钮时全屏显示?


- addEventListener 在 IE 11 中不起作用 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Flexslider 箭头未正确显示 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01