I’m currently trying to fullscreen an iFrame on a button click, similar to this website. This website has a bar that goes fullscreen with the iframed game, which is what I would ideally like to do. I can’t really figure out how to do this. If possible, I would prefer to use no JavaScript, but let me know if there is an easier method with JavaScript. I’m pretty new to coding, so any help would mean a lot.
Below is the iFrame code and the image/title of the game.
<html>
<iframe src="https://1v1.lol" style="border:0px #ffffff none;" name="" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="465px" width="740px" allowfullscreen="yes" ></iframe>
<p>
<span style="color: #000000;">
<img src="https://geometryspot.com/wp-content/uploads/2023/05/1001v1LOL.webp" style="width: 35px; position: relative; left: 15px">
<span>     1v1.lol</span>
</span>
</p>
</html>```
2
Answers
The fullscreen functionality is directly dependent on browser API and you have to use a Fullscreen API for this using some JS code. Here is an example of this:-
Now we use a little bit of JavaScript to toggle an iframe to fullscreen.
Then apply click handler event to the button with following conditions as:-
NOTE:- Fullscreen API will trigger respective browser-specific methods to request a fullscreen for an iframe.
It depends on what you mean by "fullscreen". If you want your
<iframe>
element to take the whole page, then use CSS to do such a thing.Of course, to toggle such a thing, you need to use JavaScript.
If you want your element to take the computer’s whole screen, use the
requestFullscreen()
method.Note: It may not work in the Stack Snippet, but it’ll work locally.