[Solved] How to make an iFrame to go fullscreen on a button click?

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>
Enquirer: ssk

||

Solution #1:

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.

Respondent: Jonathan Lam

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.