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 在单击按钮时全屏显示?
基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
