1

目前正在开发一个 Chrome 打包的应用程序。我已经实现了全屏功能。长话短说:

如果应用程序在全屏时退出/关闭,应用程序窗口将以全屏模式启动,但内容不是全屏,因为没有用户交互就无法全屏!

我如何全屏显示(内容脚本)

document.addEventListener("webkitfullscreenchange", function () {
  if(document.webkitIsFullScreen === true) {
    document.querySelector('.active webview').contentWindow.postMessage('fullscreen, enter', 'http://'+viewer.app.networkHost+':'+viewer.app.networkPort+'/*');
    document.body.webkitRequestFullscreen();
    $("#presenter, #slide-container .owl-item").addClass('fullscreen tenTwenty');
    $("#viewer-container, #slide-container").addClass('fullscreen thirteenSix');
    $("#scroll-left, #scroll-right, #scroll-top").addClass('scroll-fullscreen');
    $('.fullscreen').width(screen.width);
    $('.fullscreen').height(screen.height);
    $('#slide-container').trigger('refresh.owl.carousel');
  } else {
    console.log('not fullscreen');
    document.webkitCancelFullScreen();
    document.querySelector('.active webview').contentWindow.postMessage('fullscreen, exit', 'http://'+viewer.app.networkHost+':'+viewer.app.networkPort+'/*');
    $('.tenTwenty').width(1024); $('.tenTwenty').height(768);
    $('.thirteenSix').width(1366); $('.thirteenSix').height(768);
    $("#presenter, #viewer-container, #slide-container, #slide-container .owl-item").removeClass('fullscreen tenTwenty thirteenSix');
    $("#scroll-left, #scroll-right, #scroll-top").removeClass('scroll-fullscreen');
    $('#slide-container').trigger('refresh.owl.carousel');
  }
  viewer.showControls();
}, false);

创建窗口

openViewer: function(pres_id) {
var self = this;
self.current_presentation_id = pres_id;
chrome.app.window.create(
  'view/viewer.html',
  {
    id: 'presentation-viewer-'+pres_id,
    outerBounds: { width: 1024, height: 768 },
    "resizable": false,
  }, function(createdWindow) {
      // Run animation for first slide
      window.setTimeout(function() {
        createdWindow.contentWindow.window.viewer.firstSlideAnimation();
        createdWindow.contentWindow.window.viewer.toggleNavigation();
      }, 3500);

      if(createdWindow.isFullscreen() === true) {
        window.setTimeout(function() {
          //It is fullscreen I need to request fullscreen but it will not allow me
        }, 2500);
      }
    createdWindow.onClosed.addListener(function() {
      //Close all sockets on close
      chrome.sockets.tcp.getSockets(function(s) {
        $(s).each(function() {
          chrome.sockets.tcp.disconnect(this.socketId);
          chrome.sockets.tcp.close(this.socketId);
        });
      });

      /*
         Somehow here, I need to exit fullscreen maybe? This does not work of course
         createdWindow.contentWindow.document.webkitCancelFullScreen();
      */

    });
    //Get document
    console.log(createdWindow.contentWindow.window.document);
    //createdWindow.contentWindow.window;
  }
);
}

我的问题

我可以通过 webkitRequestFullscreen() 阻止应用程序全屏启动、在关闭时重置状态甚至强制全屏吗?这些都可以解决我的问题。

4

0 回答 0