I want to use HTML5 notifications:
var n = new Notification("Hello");
How can I open the tab, the notification came from?
I want to use HTML5 notifications:
var n = new Notification("Hello");
How can I open the tab, the notification came from?
Handle the onclick
event and call window.open
.
n.onclick = function() {
window.open(yourUrl);
};
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();
});
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.