Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 504
ssk Avatar asked Nov 17 '15 22:11

ssk


People also ask

How do I put the iframe button on full screen?

Follow these simple steps: Get the iframe embed code and paste in into your HTML page. Set the height and the width attributes of the iframe tag to 100% Change the CSS position of the iframe tag to 'absolute' and set the left and top CSS parameters to '0'

Can iframe go fullscreen?

You can add allowfullscreen attribute to the iframe so that you can click fullscreen button in the HTML5 player toolbar to go fullscreen.

How do I automatically open a web page in full screen mode in HTML?

Full-screen can be activated for the whole browser window by pressing the F11 key. It can be exited by pressing the Esc button. It is also possible to make a specific element in the page to enter and exit full-screen mode programmatically using Javascript Fullscreen API.

What can I use instead of iframe?

Use the object Tag as an Alternative to Iframe in HTML We can use the tag to display another webpage in our webpage. The object tag is an alternative to the iframe tag in HTML. We can use the tag to embed different multimedia components like image, video, audio, etc.


1 Answers

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.

like image 130
Jonathan Lam Avatar answered Sep 19 '22 15:09

Jonathan Lam