views:

1357

answers:

3

Im trying to close a child window with javascript and in firefox everything works fine but in chrome the window doesnt close

here is what im using

$(document).ready(function() {
    if (window.opener && !window.opener.closed)
        window.opener.location = "http://www.website.com"
    window.close();
});

I tried a suggestion on google, but to no avail.

Anyone having a similar issue or know of a work-around?

+9  A: 

I know this question is old, but I ran into the same problem. This worked for me:

window.open('', '_self', ''); //bug fix
window.close();
Warren Benedetto
Yes, this works for me, too. @Patrick should mark it as the answer.
Bill Paetzke
Why does this work?
Long Ouyang
@Long I think because the bug fix crashed with first window.open() so it should be delayed.@Warren Thanks.
Jeaffrey Gilbert
+4  A: 

if previously you open some other window by window.open()

this don't work:

window.open(...)
window.open('', '_self', '');
window.close();

but work:

window.open(...);
setTimeout(function(){
    window.open('', '_self', '');
    window.close();
}, 100);
Maxim D. Kuznetsov
A: 

Something like this should also work:

setTimeout(function() { window.close(); },50);

Max Kramnik
However a bit hacky though.
BalusC