How do you make an iframe fullscreen on button click? I've search but the ones provided only show how to make the window full screen, not iframe. Please help, I'm trying to make an embedded iframe become fullscreen on click. Thanks!
Asked
Active
Viewed 354 times
0
-
:(, still not working. – Free Online Games May 08 '17 at 22:45
1 Answers
2
You will have to do two things: make the window fullscreen, and then the <iframe>
to fill up the whole size.
You can make it go fullscreen with JS such as in this SO answer.
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;
}
See this partially working* example on JSFiddle.
*partially working because JSFiddle doesn't allow the fullscreen method because it deems it unsafe. But it should work for you.
-
-
The JS part in yourt javascript file oder section and the css part in the css file/section. – Markus May 08 '17 at 22:09
-
Uhhh, when I did that, it makes the whole background the iframe instead of fullscreen. – Free Online Games May 08 '17 at 22:29
-