7

I have this JSFiddle sample for webkitRequestFullScreen.

I'm using Chrome 2 on Mac OSX and the example does not appear to work for me. Initially I wrote my own example but the one in the link below is not written by me. Still it doesn't appear to work.

http://jsfiddle.net/2uNzk/1/

var test = document.querySelector('.test');

test.addEventListener('click', function () {

  if(test.requestFullScreen) {
    test.requestFullScreen();
  } else if(test.mozRequestFullScreen) {
    test.mozRequestFullScreen();
  } else if(test.webkitRequestFullScreen) {
    test.webkitRequestFullScreen();
  }
}, false);

however the following example does work! Only when I try to reproduce it in Plunker or JSFiddle it doesn't appear to work:

http://www.jwplayer.com/blog/using-the-browsers-new-html5-fullscreen-capabilities/

heres my plunker example:

 <!-- just to keep things in one place I put the JS here. -->
  <script type="text/javascript">
    function goFullscreen(id) {

      // Get the element that we want to take into fullscreen mode
      var element = document.getElementById(id);

      // These function will not exist in the browsers that don't support fullscreen mode yet, 
      // so we'll have to check to see if they're available before calling them.

      if (element.mozRequestFullScreen) {
        // This is how to go into fullscren mode in Firefox
        // Note the "moz" prefix, which is short for Mozilla.
        element.mozRequestFullScreen();
      } else if (element.webkitRequestFullScreen) {

        // This is how to go into fullscreen mode in Chrome and Safari
        // Both of those browsers are based on the Webkit project, hence the same prefix.
        element.webkitRequestFullScreen();

      }
      // Hooray, now we're in fullscreen mode!
    }
  </script>



  <div class="example">
    <img class="video_player" src="http://assets3.parliament.uk/iv/main-large//ImageVault/Images/id_7382/scope_0/ImageVaultHandler.aspx.jpg" id="player2">
    <button onclick="goFullscreen('player2'); return false">Click Me To Go Fullscreen! (For real)</button>
  </div>

http://plnkr.co/edit/BOhqNTEACTPmr9ebVnHs?p=preview

Any ideas? I'm baffled!

K-Dawg
  • 3,013
  • 2
  • 34
  • 52

4 Answers4

14

The webkit version does not capitalize the s of Fullscreen.

10

For anyone else looking, I found this thread that says it doesn't work on iPhones if you're calling it for an element (div, etc): https://developer.apple.com/forums/thread/133248

Paul D
  • 101
  • 1
  • 2
3

Okay I finally found the easy answer. For iOS what will work is webkitEnterFullscreen().

const docEl = document.getElementById('player') as any; // Remove as any if not using typescript
if (!docEl) return;
if (docEl.requestFullscreen) docEl.requestFullscreen();
else if (docEl.webkitRequestFullscreen) docEl.webkitRequestFullscreen();
else if (docEl.mozRequestFullScreen) docEl.mozRequestFullScreen(); // Careful to the capital S
else if (docEl.msRequestFullscreen) docEl.msRequestFullscreen();
else if (docEl.webkitEnterFullscreen) docEl.webkitEnterFullscreen(); // Magic is here for iOS
Keytrap
  • 421
  • 5
  • 14
0

Here is how I successfully did the enter and exit fullscreen. Tested with Chrome, Safari, Firefox and Opera browsers.

if (document.fullscreenElement) {
  document.exitFullscreen();
} else if (document.webkitFullscreenElement) {
  document.webkitExitFullscreen();
} else if (document.mozFullScreenElement) {
  document.mozCancelFullScreen();
} else if (document.msFullscreenElement) {
  document.msExitFullscreen();
} else {
  var puzzleFull = document.getElementById('puzzle-full');
  if (puzzleFull.requestFullscreen) {
    puzzleFull.requestFullscreen();
  } else if (puzzleFull.webkitRequestFullscreen) {
    puzzleFull.webkitRequestFullscreen();
  } else if (puzzleFull.mozRequestFullScreen) {
    puzzleFull.mozRequestFullScreen();
  } else if (puzzleFull.msRequestFullscreen) {
    puzzleFull.msRequestFullscreen();
  }
}

P.S. - I'm using a toggle button to enter/exit fullscreen of the puzzle.

RukshanJS
  • 791
  • 1
  • 7
  • 20