Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
681 views
in Technique[技术] by (71.8m points)

javascript - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The webkit version does not capitalize the s of Fullscreen.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...