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 在单击按钮时全屏显示?
基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
