添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

I have developed a chrome extension and I would like to close current page where the getClickHandler was fired

below the background.js file

chrome.contextMenus.create({
"title": "My App",
"type": "normal",
"contexts": ["all"],
"onclick": getClickHandler()

function getClickHandler() {
return function (info, tab) {
//do a job it will open a new page
// Create a new tabto the info page.
chrome.tabs.create({ url: url, });

---------------------Here I want to add script to close the current page not the create tab thenew page---------------

I tried window.close but it did not work
please help me to close the current page ..Thanks:)

Hi @Devos2022 ,
Ordinary javascript cannot close windows willy-nilly. If you want to use js to close the windows,you must open it first. One way,you could use Chrome extension.Just like this:

chrome.windows.remove(integer windowId, function callback)  

Another,if you use the old Chrome,you could do like this:

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

If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.