window.close() and self.close() not working on Chrome, looking for new solution

17,869 views
Skip to first unread message

mexica...@gmail.com

unread,
Apr 17, 2015, 1:26:29 PM4/17/15
to blin...@chromium.org
Our JavaScript to close the current window/tab after the user clicks OK, is no longer working.  I have researched it on line and tried several suggestions without success.

self.close(), window.close(), top.close() - returned error "Scripts may not close windows that were not opened by script."

I see other people having the same error.

Tried variations like,

window.open('', '_self', '');
window.close();
var win = window.open('', '_self'); win.close()

Also tried,

                function closeWindow(){
                        chrome.tabs.query({currentWindow: true, active: true}, function(tab){ // Get the current tab
                                chrome.tabs.remove(tab[0].id); // Remove the tab
                        });
                }

Also failed.

Any help will be appreciated.

Thanks.

PhistucK

unread,
Apr 17, 2015, 2:57:30 PM4/17/15
to mexica...@gmail.com, blink-dev
Copying almost the same reply from the other thread -
I do not see this error anywhere in the code.
I do see "Scripts may close only the windows that were opened by it", though. And this review suggests that the message you quoted is actually a Firefox message, so make sure you are posting to the right browser.

Generally, you cannot close windows that were opened by the user. Calling window.open("", "_self") is not opening a new window, it is reusing an existing window and as such, is not supposed to make it closable all of a sudden, I believe.

If you could close a window that you did not programmatically open, then it was a bug and it must have simply been fixed.

chrome.tabs is an extension API, not available to web pages (you can create an extension that will close windows for you, though).


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.

toke...@gmail.com

unread,
Aug 6, 2016, 3:00:18 PM8/6/16
to blink-dev, mexica...@gmail.com
 This is impossible to do

che...@isritechnologies.com

unread,
Apr 20, 2020, 9:48:24 PM4/20/20
to blink-dev, mexica...@gmail.com
Not working any code.
Please help me

Daniel Bratell

unread,
Apr 23, 2020, 1:52:35 PM4/23/20
to che...@isritechnologies.com, blink-dev, mexica...@gmail.com

Hi,

If you think this is a bug then you are probably better off filing a bug report with the necessary information to reproduce the problem. As the error message you commented indicate, it's intentional that sites can't close a tab/window unless they were the ones that opened it. If that is what you see, then it is as it's meant to be.

In general, I think StackOverflow might be a good place to ask web development questions. Unless you think it is a Chromium/Blink bug because then this is the place and the bug reporting site, https://crbug.com/ , is even better.

/Daniel

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.

To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
Reply all
Reply to author
Forward
0 new messages