5

Focus opener window not working in Chrome...

Example 1.

popunder=window.open('http://google.com','asdf','width=800,height=800');
popunder.blur();
popunder.opener.window.focus();

Example 2.

popunder=window.open('http://google.com','asdf','width=800,height=800');
popunder.blur();

x = popunder.window.open('about:blank');
x.close();

popunder.opener.window.focus();

Example 3.

popunder=window.open('http://google.com','asdf','width=800,height=800');
popunder.blur();
window.focus();

Example ... and so on.

Does anyone know a solution that works?

rjanjic
  • 2,640
  • 1
  • 15
  • 13

2 Answers2

9

The only solution that currently works in Chrome is this code inside new window:

$(".closeBtn").click( function(e) 
{
    window.open("",window.opener.name);
});

Unfortunately the solution only works under two conditions:

  • window.opener has to have it's name set on document load (window.name="WhateverName";)
  • window.open() is called on user click
Matej Balantič
  • 1,627
  • 18
  • 21
  • Works well, thx! Also if you are in a frame (I share your pain) of new window use this code to focus opener window: window.open("", window.top.opener.name); – Alexander Puchkov Jul 19 '13 at 22:55
  • It looks like you can name the opener... var randomName = 'a' + Math.random(); window.opener.name = randomName; window.open('', randomName); But even this may not always work. :( – Glen Little Nov 07 '13 at 21:16
  • Can somebody else confirm this? If it's a fact I'll remove the answer – Matej Balantič Mar 05 '14 at 15:03
1

I'm also working on this issue, currently the latest Canary build 26, breaks all of the hacks that I know about. I know there are still some sites that are working around this, but can't figure out how.

There is jquery popunder, but only if you have jquery available.