【问题标题】:onclick+ settimeout event is not working in Chromebase system for chrome extension apponclick+ settimeout 事件在 Chromebase 系统中不适用于 chrome 扩展应用程序
【发布时间】:2019-01-08 15:45:22
【问题描述】:

我已经创建了 chrome 扩展。我的代码在 Windows/Mac/Chromebook(V8) 中运行良好,但在 Chromebase 中无法运行,而用户在 3 分钟后尝试点击/捕获徽标,它没有在主页上重定向。我已经设置了 3 分钟的超时时间,它可以在所有系统上运行,而不是 Chrombase 触摸事件。

奇怪的是它只是第一次工作。

我的代码如下,来自重置超时和 DOM 元素:

    var t;  
    onload = function() {
      var webview = document.querySelector('webview');
      window.onload = resetTimer;
      // DOM Events
      document.onclick = resetTimer;
      document.onmousemove = resetTimer;
      document.onkeypress = resetTimer;
     };



    function resetTimer() {
    clearTimeout(t);
    t = setTimeout(goHome, 180000);
    // 1000 milisec = 1 sec
    }

    function goHome() {
     navigateTo('http://MyURL.com/homepage/');
    }  


  function navigateTo(url) {
    document.querySelector('webview').src = url;
    }

另外,我还在谷歌上搜索了 touchstart、touchmove 等触摸事件,但它似乎也不起作用..

可能有什么问题?请帮忙

【问题讨论】:

  • 有什么办法可以解决这个问题@wOxxOm?请帮忙
  • 它的 chrome 私有企业扩展 @wOxxOm
  • 我只能建议使用 devtools 进行调试。如果您不拥有该设备,建议您的客户设置 TeamViewer 会话。
  • 如果我们添加 touchstart、touchmove 和重置计时器等触摸事件,那么它可以工作吗?...您有什么建议?

标签: javascript google-chrome-extension settimeout ontouchlistener chromebook


【解决方案1】:

请使用Chrome.alarms 而不是settimeout。

您的代码应替换为以下代码。

var t;  
onload = function() {
  var webview = document.querySelector('webview');
  window.onload = resetTimer;
  // DOM Events
  document.onclick = resetTimer;
  document.onmousemove = resetTimer;
  document.onkeypress = resetTimer;

  document.ontouchstart = resetTimer;
  document.ontouchmove = resetTimer;
  document.ontouchend = resetTimer;   
 };

 function resetTimer() {

    chrome.alarms.clear("logoutTimer", function() {     });
    chrome.alarms.create("logoutTimer", {periodInMinutes:1});
   }


 chrome.alarms.onAlarm.addListener(function(alarm){

   navigateTo('http://dev.innovicloud.com/CHROMEAPP/');
 });



function navigateTo(url) {
  document.querySelector('webview').src = url;
 }

【讨论】:

    猜你喜欢
    • 2014-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多