最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Go to an already opened tab when a Chrome Notification is clicked - Stack Overflow

programmeradmin4浏览0评论

Javascript in a web page (not a Chrome app or extension) can create a Chrome desktop notification, and set an URL to be opened when the notification is clicked.

var notification = new Notification('Notification title', {
  icon: '.png',
  body: "Hey there! You've been notified!"
});

notification.onclick = function () {
  window.open("");
}

Is it possible to create a notification that, when is clicked, opens the tab which created that notification?

Javascript in a web page (not a Chrome app or extension) can create a Chrome desktop notification, and set an URL to be opened when the notification is clicked.

var notification = new Notification('Notification title', {
  icon: 'http://cdn.sstatic/stackexchange/img/logos/so/so-icon.png',
  body: "Hey there! You've been notified!"
});

notification.onclick = function () {
  window.open("http://stackoverflow./a/13328397/1269037");
}

Is it possible to create a notification that, when is clicked, opens the tab which created that notification?

Share Improve this question edited Apr 6, 2015 at 12:50 Lighty asked Apr 6, 2015 at 12:39 LightyLighty 711 silver badge5 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 14 +250

Yes.

notification.onclick = function () {
  window.focus();
}

Instead of window.open, try using:

window.location = "https://stackoverflow./a/13328397/1269037"

That worked for me.

发布评论

评论列表(0)

  1. 暂无评论