单击Chrome通知时转到已打开的选项卡

Lig*_*hty 3 javascript notifications google-chrome web-notifications

网页中的Javascript(不是Chrome应用或扩展程序)可以创建Chrome桌面通知,并设置在单击通知时要打开的URL.

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

notification.onclick = function () {
  window.open("http://stackoverflow.com/a/13328397/1269037");
}
Run Code Online (Sandbox Code Playgroud)

是否可以创建一个通知,单击何时打开创建该通知的选项卡?

Zec*_*umo 6

是.

notification.onclick = function () {
  window.focus();
}
Run Code Online (Sandbox Code Playgroud)


小智 2

而不是window.open,请尝试使用:

window.location = "https://stackoverflow.com/a/13328397/1269037"
Run Code Online (Sandbox Code Playgroud)

这对我有用。