What exactly do you want to achieve? To set the focus inside the other window to the first link / button / form field / whatever? Or to make the other window (browser tab) the active browser tab?
Anyways - maybe the opener.focus() call doesn't work because both windows are not served from the same origin. Try setting up a communication channel via postMessage to resolve this. So in the opener document, listen for an event like this:
window.addEventListener('message', function (event) {
window.focus();
}, false);
And in the opened window, send the message like this:
opener.postMessage('foo', '*');
Sadly, I can't test if this is working right now. (I guess it should, though...)
A few things to add, though:
- Some legacy crap browsers don't support postMessage (see caniuse.com). There are workarounds, though. :)
- I used the W3 standard notation for attaching the event listener. IE8 and below use their proprietary
attachEvent equivalent.
- You should replace the
'*' origin wildcard with the actual origin of the opener window.
- In the message event listener function, you should inspect event.origin and only run your actual payload if the origin is correct.
answered 2013-06-22T11:35:18.323