使用Fullscreen& amp; Chrome浏览器网页视图总在最前面

时间:2014-03-19 17:55:30

标签: google-chrome google-chrome-extension google-chrome-devtools google-chrome-app

我正在开发使用网络视图打开的Chrome应用并加载我们的网页。我正在尝试制作一个可以锁定网络视图的应用,这样当有人参加测试时,他们无法摆脱它或使用其他东西来尝试欺骗。所以我现在遇到的问题是我无法让全屏和AlwaysOnTop互相合作。有没有办法做到这一点,或者这两件事情不会合在一起,如果没有,那就是让他们去工作或者我需要采取另一个方向。我目前正在使用Chrome测试版运行我的应用程序,因为alwaysOnTop还没有使用稳定版本。这是我的代码 main.js

chrome.app.runtime.onLaunched.addListener(function() {
    chrome.app.window.create('browser.html', {
      state: "fullscreen",
     "resizable": false,
     'alwaysOnTop': true
   }, 

  function(win) {
    win.contentWindow.document.addEventListener('keydown', function(e) {
        if(e.keyCode == 27){
           e.preventDefault();
    }
   });
   win.contentWindow.document.addEventListener('keyup', function(e) {
        if(e.keyCode == 27){
           e.preventDefault();
    }
    });
   });
  });

任何帮助或某种类型的指示都会很棒。我只能在设置边界时让alwaysontop工作,但这会显示最小化最大化并退出哪种类型会破坏我正在尝试做的目的。谢谢你提前。

1 个答案:

答案 0 :(得分:0)

你可能想看看" overrideEscFullscreen"允许。 见https://code.google.com/p/chromium/codesearch#chromium/src/chrome/test/data/extensions/platform_apps/prevent_leave_fullscreen_old/manifest.json&q=overrideEscFullscreen&sq=package:chromium&type=cs

manifest.json

{
  "name": "Test app for leaving fullscreen rules",
  "version": "1",
  "app": {
    "background": {
      "scripts": ["main.js"]
    }
  },
  "permissions": [
    "fullscreen", "overrideEscFullscreen"
  ]
}

main.js

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('main.html', {}, function(win) {
    // The following key events handler will prevent the default behavior for
    // the ESC key, thus will prevent the ESC key to leave fullscreen.
    win.contentWindow.document.addEventListener('keydown', function(e) {
      e.preventDefault();
    });
    win.contentWindow.document.addEventListener('keyup', function(e) {
      e.preventDefault();
    });
  });
});
相关问题