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
2 Answers
Reset to default 2before 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.