首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ServiceWorker Chrome推送通知-转发到新页面

ServiceWorker Chrome推送通知-转发到新页面
EN

Stack Overflow用户
提问于 2015-09-10 14:35:01
回答 1查看 313关注 0票数 1

我想要做的是看看我的网站的标签是否在Chrome中打开,如果是的话,请关注它,并将它们转发到我正在传递的新URL。

作为参考,当您看到"event.notification.data“时,它将是像"https://www.example.com/mobile/profile.php?id=Webmaster”这样的链接。

我可以将注意力集中在选项卡上,但不能将该选项卡重定向到我存储在"event.notification.data“中的URL。

这是我的密码

代码语言:javascript
复制
self.addEventListener('notificationclick', function(event) {
  event.notification.close();
  event.waitUntil(
    clients.matchAll({  
      type: "window" 
    })
    .then(function(clientList) {  
      // loop through all the tabs
      for (var i = 0; i < clientList.length; i++) {  
        var client = clientList[i]; 
        //check if a tab starts with the websites name 
        if (client.url.indexOf("https://www.example.com/mobile") == 0 && 'focus' in client){
          //a tab matched! Check if the data (a link) is there

          //------
          //THIS IS WHERE I NEED HELP
          //------
          if(event.notification.data != ''){
            //yes! event.notification.data is a link, focus on the tab and forward them there
            client.focus();
            client.navigate(event.notification.data);
          } else {
            //no! event.notification.data was blank, focus on the tab and forward them to the general site
            client.focus();
            client.navigate('https://www.example.com/mobile');
          } 

        }
      }  
      if (clients.openWindow) {
        if(event.notification.data != ''){
          clients.openWindow(event.notification.data);
        } else {
          clients.openWindow('https://www.heftynet.com/mobile');
        }  
      }
    })
  );
});
EN

Stack Overflow用户

回答已采纳

发布于 2015-09-10 15:22:31

看起来client.navigate()还没有实现(截至2015年9月10日),甚至在Canary中也没有。几个月前才具体说明的。,2015年6月。这是特征状态页和相关的铬票。一旦实现了navigate(),您的代码可能就能工作。

票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32504823

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档