Closing popup window created by Google Chrome extension

你离开我真会死。 提交于 2019-11-27 11:35:54

Try window.close(), but that probably wouldn't work either.

As you are creating regular window (rather than browser action popup), then you can close it using chrome.tabs.remove() from a background page. You can also detect this window from a background page. Something like:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if(changeInfo.status == "loading") {
        if(tab.url == "http://www.delicious.com/save") {
            chrome.tabs.remove(tabId);
        }
    }
});

I am not sure how Chrome treats created windows though - as tabs or windows. If as windows then above code will be a little different.

I found a very easy work around to this. You just set the selected tab to True and the Popup disappears, like this...

// remove popup by selecting the tab
chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.update(tab.id, { selected: true } )
});

I've found this solution: chrome.tabs.update({ active: true }); This single line of code closes the browser action's popup window. You even don't need to pass tab.id there because by default it is set to id of the current tab. I run it in background page but seems it can be run everywhere in the extension.

getSelected not working for me, so i found this solution

chrome.tabs.create({url: 'https://www.google.com', active: false});

in background.js you need just

window.close();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!