Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onclick go full screen

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?

like image 763
David Avatar asked Oct 10 '10 14:10

David


People also ask

How do you make a click full screen?

Full-screen can be activated for the whole browser window by pressing the F11 key. It can be exited by pressing the Esc button.

How do I make Div full screen on button click?

You'll want a fixed position element at 100% width and height , if you don't have a background color or image you'll be able to click through it. Set z-index higher then all other elements to ensure it is at the front if you need that.

How do I make HTML page full screen?

Toggling fullscreen mode If the value is null , the document is currently in windowed mode, so we need to switch to fullscreen mode; otherwise, it's the element that's currently in fullscreen mode. Switching to fullscreen mode is done by calling Element. requestFullscreen() on the <video> element.


2 Answers

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(); } 
like image 37
alex Avatar answered Sep 18 '22 08:09

alex


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:

Mozilla Developer Network

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

Chrome Fullscreen API

jQuery fullscreen event plugin, version 0.2.0

jquery-fullscreen-plugin

like image 90
Zuul Avatar answered Sep 21 '22 08:09

Zuul