javascript - 在 Kiosk 模式下无法读取未定义的属性 'onLaunched'

标签 javascript jquery google-chrome kiosk-mode

我想检测 Google Chrome 信息亭模式。我正在使用此代码来检测信息亭模式。

chrome.app.runtime.onLaunched.addListener(function (launchData) {

            alert("chrome");
            launchData.isKioskSession; //true or false
        });

我收到此错误。

未捕获类型错误:无法读取未定义的属性“onLaunched”

我需要添加一些引用吗?

最佳答案

https://developer.chrome.com/apps/app_lifecycle#launch_data

它说:

Depending on how your app is launched, you may need to handle launch data in your event page. By default, there is no launch data when the app is started by the app launcher. For apps that have file handlers, you need to handle the launchData.items parameter to allow them to be launched with files.

我相信您需要首先检查 launchData 对象是否存在。

chrome.app.runtime.onLaunched.addListener(function (launchData) {
  alert("chrome");
  if(typeof launchData !== 'undefined') {
    // Perform actions with launchData
    launchData.isKioskSession; //true or false
  }
});

关于javascript - 在 Kiosk 模式下无法读取未定义的属性 'onLaunched',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27857506/

相关文章:

jquery,为改变背景添加动画

javascript - 如何在 jQuery slider 旋钮上显示当前 slider 值?

node.js - 如何在 Express 4 中正确设置链接预取 header ?

javascript - 我如何确定 DOM 元素的 XPath?

javascript - Ace.js 以编程方式添加新行

javascript - 在执行期间扫描 JSP 页面时,将首先扫描页面的哪一部分

javascript - 如何使用 ReactJs 将网络摄像头流式传输到移动浏览器?

javascript - 解析标签的正则表达式(或其他建议)

javascript - 无法使用 jQuery/Javascript 从表单中检索值

google-chrome - 将 SVG 图像从浏览器复制到剪贴板