最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to close the Current opened Tab and go back to previous (Parent) Tab - Stack Overflow

programmeradmin0浏览0评论

It is not a duplicate question please Dear All, I am new to Jquery, Please help me how to close the Current opened Tab in a application using Jquery on click of YES/Confirm button in a model window as shown in a image. I have tried below function, its not closing current tab instead it closed all the tabs. Please help me

window.open('', '_self').close();
         window.top.close();
         window.close();

It is not a duplicate question please Dear All, I am new to Jquery, Please help me how to close the Current opened Tab in a application using Jquery on click of YES/Confirm button in a model window as shown in a image. I have tried below function, its not closing current tab instead it closed all the tabs. Please help me

window.open('', '_self').close();
         window.top.close();
         window.close();
Share Improve this question edited Mar 14, 2019 at 0:58 Barmar 784k57 gold badges548 silver badges659 bronze badges asked Mar 14, 2019 at 0:46 ShankarShankar 711 silver badge7 bronze badges 5
  • JavaScript can't manipulate tabs. – Barmar Commented Mar 14, 2019 at 0:58
  • Since i am opening the window/tab not using window.open so. I am able to close the particular tab by TabID using programmatically – Shankar Commented Mar 14, 2019 at 15:54
  • JS can only close a window/tab that it opened. If you don't use window.open, you can't close it. – Barmar Commented Mar 14, 2019 at 15:56
  • I am able to close the particular tab by TabID using programmatically You keep stating that, but it's not true. Why do you think you're able to do that? Where do you get the TabID from? – Barmar Commented Mar 14, 2019 at 15:58
  • I think a browser extension can do this, but not JavaScript in an ordinary page. – Barmar Commented Mar 14, 2019 at 15:58
Add a ment  | 

2 Answers 2

Reset to default 2

before you close the current tab, you need to open it using "window.open()". the window.close button works only the windows that opened by it.

You can close the current tab with this javascript line:

window.top.close();

But there are things that you should keep in mind:

  • This will only work if the tab is also opened programmatically.

    By using window.open();, you can close the opened tab with the javascript line above.

  • Not all browsers support this solution

You can also visit this link for reference. I hope this helps.

发布评论

评论列表(0)

  1. 暂无评论