How do I focus on a 1-minute-a-minute popup? Remembering that the popup is minimized and I want to leave it "in evidence" on the user's screen.
How do I focus on a 1-minute-a-minute popup? Remembering that the popup is minimized and I want to leave it "in evidence" on the user's screen.
The way to do this is with the function focus
of the object window
returned by opening the window.
For example:
var janela = window.open('http://www.google.com.br');
setInterval(function() {
janela.focus();
}, 60000);
The problem is that this does not seem to work across multiple browsers, since they want to prevent malicious scripts from setting the user's focus on a particular window, such as advertising.
Tests performed:
So my suggestion is to avoid using popup. First and foremost, this is often an attempt to replicate functionality of desktop programs in web applications. Secondly because I always see this causing many side effects and bumping into various limitations, such as Firefox, which opened the popup in a new tab.
Think of a workaround, such as notifications here from StackOverflow or Facebook, for example.
Update
I tested an alternative, reopening the popup at the given interval:
setInterval(function() {
window.open('http://www.google.com.br', 'minha_janela').focus();
}, 60000);
However, the result is the same in different browsers, ie only IE gives the focus back to the popup. The difference is that the page refreshes with each opening and, if the popup has been closed, it is reopened.
var p = window.open("about:blank", "_blank", "width=610,height=610");
p.location = "http://www.google.com.br";
setInterval(function(){
p.focus();
}, 60000);
Call var p
before anything else in your routine to prevent it from falling into the popup blocker.