Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communicating back to parent from a Webkit notification

I'm using webkitNotifications and createHTMLNotification, etc. to successfully create a notification in Chrome (Windows).

Now I would really like to have the notification window communicate back (or at least set the focus to) the tab/window that created the notification (which is part of the spec). I realize it's still in the early phases for this feature, but I thought maybe someone knows a way. I tried:

window.opener.focus();

from the notification window, but it didn't work.

This page... http://www.thecssninja.com/javascript/web-notifications

says... "Bringing focus back to the window that called the notification, as stated in the proposal by using window.opener.focus(), doesn’t currently work."

I was hoping it was either out of date or that someone might know a workaround.

Thanks for any information you can share.

Jim

like image 895
jbobbins Avatar asked Sep 07 '10 07:09

jbobbins


4 Answers

I know this question is old, but here's what I'm using to return focus to the window/tab that created a notification:

notification.onclick = function() {window.focus(); this.cancel();}
like image 130
Mzzzzzz Avatar answered Nov 19 '22 13:11

Mzzzzzz


notification.click= function() { alert('whatever'); };

Works for me, but of course it's ugly...

like image 23
Markus Avatar answered Nov 19 '22 13:11

Markus


There is a solution to communicate between windows using shared webworkers.

I built Toobify.com with a "remote" button, a webkitNotification window that controls the parent. Have a look at the source of the project - if your feeling brave.

I'd also like to set focus to go back to this window. Seems to be a feature of the textbased notification not the HTML kind.

like image 42
Drew Avatar answered Nov 19 '22 15:11

Drew


Short, Sweet, and Complete

It took me several hours, but I've got a basic example:

  • SharedWorker + Desktop Notification Demo
  • SharedWorker + Desktop Notification Repo

You'll have to excuse the brevity of the README, it's 3:30am and I was sprinting.

Ask me questions and I'll answer them and clean up the docs.

like image 1
coolaj86 Avatar answered Nov 19 '22 14:11

coolaj86