I'm creating a web-app for the upcoming Chrome Web-store. Is there a way to simulate F11 being pressed? Or simply a command that will make the current window go full screen?
-
Possible duplicate: http://stackoverflow.com/questions/1125084/how-to-make-in-javascript-full-screen-windows-stretching-all-over-the-screen – Anderson Green Jun 03 '13 at 23:53
-
Possible duplicate of [Set window to fullscreen (REAL fullscreen; F11 functionality) by javascript](http://stackoverflow.com/questions/7179535/set-window-to-fullscreen-real-fullscreen-f11-functionality-by-javascript) – Jamie Barker Nov 01 '16 at 11:31
-
Possible duplicate of [How to make the window full screen with Javascript (stretching all over the screen)](https://stackoverflow.com/questions/1125084/how-to-make-the-window-full-screen-with-javascript-stretching-all-over-the-scre) – Shawn J. Molloy Jul 15 '18 at 17:13
9 Answers
I realize this is a very old question, and that the answers provided were adequate, since is active and I came across this by doing some research on fullscreen, I leave here one update to this topic:
There is a way to "simulate" the F11 key, but cannot be automated, the user actually needs to click a button for example, in order to trigger the full screen mode.
Toggle Fullscreen status on button click
With this example, the user can switch to and from fullscreen mode by clicking a button:
HTML element to act as trigger:
<input type="button" value="click to toggle fullscreen" onclick="toggleFullScreen()">
JavaScript:
function toggleFullScreen() { if ((document.fullScreenElement && document.fullScreenElement !== null) || (!document.mozFullScreen && !document.webkitIsFullScreen)) { if (document.documentElement.requestFullScreen) { document.documentElement.requestFullScreen(); } else if (document.documentElement.mozRequestFullScreen) { document.documentElement.mozRequestFullScreen(); } else if (document.documentElement.webkitRequestFullScreen) { document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT); } } else { if (document.cancelFullScreen) { document.cancelFullScreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.webkitCancelFullScreen) { document.webkitCancelFullScreen(); } } }
Go to Fullscreen on button click
This example allows you to enable full screen mode without making alternation, ie you switch to full screen but to return to the normal screen will have to use the F11 key:
HTML element to act as trigger:
<input type="button" value="click to go fullscreen" onclick="requestFullScreen()">
JavaScript:
function requestFullScreen() { var el = document.body; // Supports most browsers and their versions. var requestMethod = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullScreen; if (requestMethod) { // Native full screen. requestMethod.call(el); } else if (typeof window.ActiveXObject !== "undefined") { // Older IE. var wscript = new ActiveXObject("WScript.Shell"); if (wscript !== null) { wscript.SendKeys("{F11}"); } } }
Sources found along with useful information on this subject:
How to make in Javascript full screen windows (stretching all over the screen)
How to make browser full screen using F11 key event through JavaScript
-
1@Zuul - I referenced your answer to answer [this question](http://stackoverflow.com/questions/7495373/how-to-make-browser-full-screen-using-f11-key-event-through-javascript/25245972#25245972), however I updated the JS code to add IE compatibility. – Jamie Barker Aug 11 '14 at 15:13
-
3
-
1The IE-specific fullscreen methods are `msRequestFullscreen` and `msExitFullscreen` (note the lower-case `s`) – RevanProdigalKnight Jun 03 '15 at 15:09
-
How would this code be modified for Chrome-only (not cross-browser)? – johny why Aug 27 '15 at 04:39
-
1
-
Pretty sure the first test should be `if (!document.fullScreenElement && !document.mozFullScreen && !document.webkitIsFullScreen) {` – Lawrence Dol Feb 22 '19 at 20:10
-
-
@LawrenceDol Can you be more specific and let us know what browser complained of what and where? – Zuul Feb 26 '19 at 17:56
-
It's possible with JavaScript.
var elem = document.getElementById("myvideo");
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
}
-
10+1. I hate websites/apps resizing my browser. If I need to resize it or fullscreen it I'll do it myself! – Azz Oct 10 '10 at 14:36
-
2If you prefer to smoothe over the various browser implementations, try Screenfull.js (https://sindresorhus.com/screenfull.js/) - it works a treat! – simonhamp Sep 07 '16 at 10:17
-
1It exists full screen on page load. what can I do to prevent that? – Arash Ghasemi Rad Jan 05 '20 at 15:26
-
I tried it for videos and it works, but I can't seem to make it work for other files, such as gltf. Have any ideas as to why that's happening? – TheQuantumMan Jul 26 '22 at 14:06
Short personal bookmarklet version
javascript: document.body.webkitRequestFullScreen();
go fullscreen ← You can drag this link to your bookmark bar to create the bookmarklet, but you have to edit its URL afterwards: Delete everything before javascript
, including the single slash: http://delete_me/
javascript:
[…]
This works for me in Google Chrome. You have to test whether it works in your environment and otherwise use a different wording of the function call, e.g. javascript:document.body.requestFullScreen();
– see the other answers for the possible variants.
Based on the answers by @Zuul and @default – thanks!

- 1
- 1

- 3,820
- 1
- 37
- 34
-
I found I had to add a trigger to the page in Firefox (mobile and desktop) to stay within the security restrictions. I made the button click both enter fullscreen and delete itself. `javascript:void%20document.body.appendChild((e=%3E%7Be.onclick=()=%3E%7Bdocument.documentElement.requestFullscreen();e.parentNode.removeChild(e)%7D;e.innerHTML='FULLSCREEN';e.style='position:fixed;left:0;top:0;z-index:999999999999';return%20e%7D)(document.createElement('BUTTON')))` and use `void` to avoid replacing the current doc with the function's return value. – Walf Apr 07 '20 at 13:18
If you want to switch the whole tab to fullscreen (just like F11 keypress) document.documentElement
is the element you are looking for:
function go_full_screen(){
var elem = document.documentElement;
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) {
elem.webkitRequestFullscreen();
}
}

- 106
- 2
- 10
-
Is there a difference between using `document.documentElement` and `document.body` (like @Zuul does in his older answer above)? – Aaron Thoma Sep 26 '17 at 17:17
I tried other answers on this question, and there are mistakes with the different browser APIs, particularly Fullscreen
vs FullScreen
. Here is my code that works with the major browsers (as of Q1 2019) and should continue to work as they standardize.
function fullScreenTgl() {
let doc=document,elm=doc.documentElement;
if (elm.requestFullscreen ) { (!doc.fullscreenElement ? elm.requestFullscreen() : doc.exitFullscreen() ) }
else if (elm.mozRequestFullScreen ) { (!doc.mozFullScreen ? elm.mozRequestFullScreen() : doc.mozCancelFullScreen() ) }
else if (elm.msRequestFullscreen ) { (!doc.msFullscreenElement ? elm.msRequestFullscreen() : doc.msExitFullscreen() ) }
else if (elm.webkitRequestFullscreen) { (!doc.webkitIsFullscreen ? elm.webkitRequestFullscreen() : doc.webkitCancelFullscreen()) }
else { console.log("Fullscreen support not detected."); }
}

- 63,018
- 25
- 139
- 189
Here are a couple of ways to do that:
I'd suggest, provide a popup asking the user if s/he wants to go full screen and then call this javascript accordingly.

- 9,896
- 2
- 31
- 41
-
https://meta.stackexchange.com/questions/225370/your-answer-is-in-another-castle-when-is-an-answer-not-an-answer – T.J. Crowder Mar 19 '18 at 12:54
-
//set height of html
$("html").css("height", screen.height);
//set width of html
$("html").css("width", screen.width);
//go to full screen mode
document.documentElement.webkitRequestFullscreen();

- 112
- 3
var elem = document.getElementById("myvideo");
function openFullscreen() {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.mozRequestFullScreen) { /* Firefox */
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullscreen) { /* Chrome, Safari & Opera */
elem.webkitRequestFullscreen();
} else if (elem.msRequestFullscreen) { /* IE/Edge */
elem.msRequestFullscreen();
}
}
//Internet Explorer 10 and earlier does not support the msRequestFullscreen() method.

- 145
- 1
- 4
so simple try this
<div dir="ltr" style="text-align: left;" trbidi="on">
<!-- begin snippet: js hide: false console: true babel: null -->

- 1
- 3