Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with window.close and chrome

I'm trying to close a child window with JavaScript, and in Firefox everything works fine but in Chrome the window doesn't close.

Here is what I'm 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?

like image 906
mrpatg Avatar asked Jan 09 '10 06:01

mrpatg


People also ask

Why window Close is not working in Chrome?

close() function won't work due to Chrome Security feature which not allow close the current window by JavaScript window. close(). If you check the message in the Chrome Developer Tool Console, you will find such message: Scripts may close only the windows that were opened by it.

Why is my Chrome closing by itself?

First: Try these common Chrome crash fixesYour computer may have run out of memory, and can't load the site while also running your apps, extensions, and programs. To free up memory: Close every tab except for the one that's showing the error message. Quit other apps or programs that are running.

How do I stop Chrome from auto closing?

Click the 'Extensions' tab, locate 'Chrome Toolbox by Google,' and then click the 'Options' link under the description of the extension. Check the box next to 'Confirm Before Closing Multiple Tabs' in the 'Tabs' section to automatically update your browser's settings.


2 Answers

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

window.open('', '_self', ''); //bug fix window.close(); 
like image 179
Warren Benedetto Avatar answered Sep 22 '22 03:09

Warren Benedetto


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); 
like image 32
Maxim D. Kuznetsov Avatar answered Sep 20 '22 03:09

Maxim D. Kuznetsov