Fixing Chrome window.close not working with javascript

If you have been trying to close a window in Chrome using window.close() in your JavaScript code, but it doesn't seem to be working, there are a few things that you can try to fix the issue.

  1. 1. Make sure the window was opened by your script
  2. 2. Delay the close command
  3. 3. Enable pop-ups in Chrome

1. Make sure the window was opened by your script

Chrome has a security feature that prevents scripts from closing windows that were not opened by the same script. So, if the window you are trying to close was not opened by your script, window.close() will not work. Make sure that the window was opened by your script, and not by the user or another script.

2. Delay the close command

Chrome has a bug that prevents window.close() from working if it is called immediately after the window is opened. To fix this, delay the call to window.close() by a few milliseconds using setTimeout(). For example:

  var win ='');
  setTimeout(function() {
  }, 100);

3. Enable pop-ups in Chrome

If pop-ups are blocked in Chrome, window.close() will not work. To fix this, you can enable pop-ups in Chrome settings. Go to Settings > Privacy and security > Site Settings > Pop-ups and redirects, and make sure that "Allowed" is selected.

By following these steps, you should be able to fix the issue with window.close() not working in Chrome with JavaScript.

Click to rate this post!
[Total: 0 Average: 0]

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Go up

Below we inform you of the use we make of the data we collect while browsing our pages. You can change your preferences at any time by accessing the link to the Privacy Area that you will find at the bottom of our main page. More Information