Close the current tab and open a new tab using JavaScript. On Chrome or any other browser.
Asked
Active
Viewed 2,136 times
-1
-
Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). And more importantly, please read [the Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922). You might also want to learn about [Minimal, Complete, and Verifiable Examples](http://stackoverflow.com/help/mcve). – Andrew Bone Nov 05 '18 at 12:10
-
Possible duplicate of [How to close current tab in a browser window?](https://stackoverflow.com/questions/2076299/how-to-close-current-tab-in-a-browser-window) – Andrew Bone Nov 05 '18 at 12:11
2 Answers
0
Try this:
window.open('http://www.google.com','_blank');
window.setTimeout(function(){this.close();},1000);

P.Banerjee
- 189
- 2
- 14
-
current tab should opened from other tab. Otherwise it'll not close. No browser will allow to close the current tab if it opened manually because of security concern. – Vishnu Prasanth G Jan 22 '19 at 20:09
0
- Close the current tab
You can't close the current tab until and unless it has parent reference
Its simple, if the current tab is opened by self I mean, you went to browser and typed the url in the url bar can't be closed with the javascript. Because of security reasons browsers will not allow these type of things.
If you try the following code
window.close();
you'll get following warning message by browser
Scripts may close only the windows that were opened by it.
If the tab is opened with window.open, right click on the link and opened on anchor tag then following should work
window.close();
self.close();
- Opening new tab using the javascript :
window.open("https://stackoverflow.com");

Vishnu Prasanth G
- 1,133
- 12
- 12