i have the below code
this code adds a button that makes an iframe go fullscreen when clicked
i need to add a javascript code to automatically click this button when site loads and the iframe becomes fullscreen when site loads
what code should i add and where should i add it ?
Thanks
.
<center><button id="full" style="color:blue;margin: 15px;;font-size:300%;" onclick="goFullscreen('cowboy'); return false">Fullscreen</button></center>
<script>
function goFullscreen(id) {
var element = document.getElementById(id);
if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullScreen) {
element.webkitRequestFullScreen();
}
}
</script>
.
i found some codes searching about this
but i dont actually know where to put them in my code
2
Answers
Browsers do not allow websites to trigger fullscreen mode on load. There must be a user interaction. You can’t fake one by simulating clicking on a button with JS; the browser knows the difference.
In javascript, you can create something called IIFE (Immediately Invoked Function Expression). These are functions which get immediately invoked by default. You can just update your code like this to achieve this:
I.e., by just wrapping your function inside () and calling it immediately by adding () in the end.
Here is the complete HTML code: