简体   繁体   中英

webkitRequestFullScreen not working?

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!

webkit 版本没有将Fullscreens大写。

对于其他人,我发现这个线程说如果您为元素(div 等)调用它,它在 iPhone 上不起作用: https : //developer.apple.com/forums/thread/133248

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM