I have the following anchor tag:
<a href="#" onclick="launchFullscreen(document.documentElement);">Full-screen</a>
Which uses the following lines of code that I've gathered from a tutorial:
<script>
// Find the right method, call on correct element
function launchFullscreen(element) {
if (element.requestFullscreen) {
element.requestFullscreen();
}
else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
}
else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
}
else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}
function exitFullscreen() {
if (document.exitFullscreen) {
document.exitFullscreen();
}
else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
}
else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
else if (element.msExitFullscreen) {
element.msExitFullscreen();
}
}
function dumpFullscreen() {
console.log("document.fullscreenElement is: ", document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement);
console.log("document.fullscreenEnabled is: ", document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled || document.msFullscreenEnabled);
}
// Events
document.addEventListener("fullscreenchange", function (e) {
console.log("fullscreenchange event! ", e);
});
document.addEventListener("mozfullscreenchange", function (e) {
console.log("mozfullscreenchange event! ", e);
});
document.addEventListener("webkitfullscreenchange", function (e) {
console.log("webkitfullscreenchange event! ", e);
});
document.addEventListener("msfullscreenchange", function (e) {
console.log("msfullscreenchange event! ", e);
});
// Add different events for full-screen
</script>
This works perfectly fine to enter full-screen mode, however when the user leaves the page (by clicking a link), it will exit full-screen mode.
Is there a way that I can make the website stay in the full-screen mode once the anchor tag is clicked, and then only exit this mode only when the ESC button or Full-screen hyperlink is pushed again?
Press Esc. The Esc key, also known as the Escape key, helps you exit a mode or stop a sequence. You can find the Esc key on the top-left-corner of your keyboard. In some apps like media players or computer games, the Esc key also allows you to exit full screen mode.
The keyboard methods used to move out of full-screen mode: Esc key (top left of your keyboard) brings the top menu and taskbar. Fullscreen (F4) key toggles from full-screen to a smaller sized window.
Whenever the URL changes, full screen mode is canceled. The only non-hack-y way can prevent this by happening is by using a SPA, Single Page Application, library which manages state by using the fragment url (#fragment
) to circumvent this issue. Here are some good ones:
If you want to go all out you can use an MVC framework which supports fragment routing:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With