适用于iPad,iPhone的Safari全屏

时间:2016-03-14 11:28:49

标签: javascript

遵循此代码,Safari中fullScreencancelFullScreen的代码是什么?:

var docEl = document.documentElement;

if      (docEl.requestFullScreen)       docEl.requestFullScreen();
else if (docEl.msRequestFullscreen)     docEl.msRequestFullscreen();
else if (docEl.mozRequestFullScreen)    docEl.mozRequestFullScreen();
else if (docEl.webkitRequestFullScreen) docEl.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);

1 个答案:

答案 0 :(得分:-1)

将您的身份ID更改为“正文”并尝试此

<script type="text/javascript">
var is_safari = navigator.userAgent.indexOf("Safari") > -1;
      var elem = document.getElementById("body");

if((navigator.userAgent.match(/iPhone/i)) || 
 (navigator.userAgent.match(/iPod/i))) {
  if (is_safari){

    elem.onclick = function() {
        req = elem.requestFullScreen || elem.webkitRequestFullScreen || elem.mozRequestFullScreen;
        req.call(elem);
    }
    }
 }
 $(document).keyup(function(e) {
     if (e.keyCode == 27) { // escape key maps to keycode `27`
 elem.webkitExitFullScreen();
    }
});
 </script>