Reputation: 4113
I am using the code found in this answer to generate a desktop notification, but I can't figure out how to get it to take me back to the page when I click on the notification.
The default behavior is to move the focus to the viewport of the notification's related browsing context.
But when I click on the notification without specifying an onclick
, it just closes the notification. When I try using window.focus()
it also just closes the notification.
You can see my altered code here. I added a setTimeout
to allow me to switch tabs before it fires, and removed the onclick
event.
I'm using chrome 59 on macOS serria if that matters.
Upvotes: 0
Views: 355
Reputation: 4175
you have put your onclick
handler outside the timeout on the object notification
and declaring notification
reference inside timeout, so you are not getting the proper object while assigning the onlick
, instead do it inside timeout.
It is not working in jsBin for some reason (may be they are creating nested window or iframe, because window.parent.parent.focus();
works) but it will work in your case, just try it! I have just modified your code, or here is a new bin
Upvotes: 1