5
I am developing a chat with Websocket and I have a problem, when I send a message to a friend, he receives the desktop notification (from the browser he is) and when he clicks on the notification he goes to the conversation window of the person who sent the message to him.
What I want is at least when the user clicks on the notification go to the tab where the chat is without giving the refresh of the page, the excerpt I did was like this, but it updates the page and does not go to the "chat tab":
notification.onclick = function () {
window.open('http://localhost/pullchat', '_self');
};
The complete code of the notification function:
//Função de notificação de mensagens
function notifyMe(nome, mensagem, id) {
if (!Notification) {
alert('Notifications are supported in modern versions of Chrome, Firefox, Opera and Firefox.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
var notification = new Notification( nome, {
icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
body: mensagem,
});
//------------------------AQUI QUE ESTÁ O PROBLEMA-------------------------------
notification.onclick = function () {
window.open('http://localhost/pullchat', '_self');
};
}