0

I want to use HTML5 notifications:

var n = new Notification("Hello");

How can I open the tab, the notification came from?

Marco Scabbiolo
  • 7,203
  • 3
  • 38
  • 46
Michael
  • 32,527
  • 49
  • 210
  • 370

3 Answers3

0

Handle the onclick event and call window.open.

n.onclick = function() { 
    window.open(yourUrl);
};
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
0

Add an event listener for the click event and then use window.focus. For example:

var n = new Notification("Hello");

n.addEventListener("click", function() {
    window.focus();
});
Peter Josling
  • 1,036
  • 8
  • 6
0

As far as I know, java script does not know if there are any other tabs open and surely not which websites you currently browse.

With a notification you can only open the tab where the notification came from, which should be the default behavior, if you click the notification.

Leifb
  • 370
  • 7
  • 20