Is there any easy work around to close the current tab and open a new tab by javascript?
Asked
Active
Viewed 1.7k times
6
-
2Open the URL in the current tab – Tushar Aug 25 '15 at 07:14
-
@Tushar Will that have a back button? I need to disable the back button in browser. – Subash L Aug 25 '15 at 07:20
4 Answers
5
Try below :
window.open('http://www.google.com','_blank');window.setTimeout(function(){this.close();},1000)

Nikhil Maheshwari
- 2,198
- 18
- 25
5
you can use location.replace
for same goal:
window.location.replace('https://stackoverflow.com/');
https://developer.mozilla.org/en-US/docs/Web/API/Location/replace

Muhammed Moussa
- 4,589
- 33
- 27
1
window.open(url,'_blank');
this.close();
window.open will open the new tab according to the user browser settings only. Sorry that I didn't find any way to open an url in new tab if the user's browser settings wont allow you to.
In browser settings, set it to allow popups and then try. This will work.
Instead, to disable back button you can use options given in this page

Kevin Sebastian Fernandez
- 131
- 2
- 8
-
http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-using-javascript this will explain you further about we have no option to open new tab unless the browser settings allow us to. – Kevin Sebastian Fernandez Aug 25 '15 at 08:04
1
var win = window.open('/Employees/GetAttendenceDataBySelectedData/?attendDateString=' + $("#AttendDate").val() + ', "_blank');
window.top.close();

slfan
- 8,950
- 115
- 65
- 78

Kushan Viduranga
- 21
- 1
-
Please provide some explanation of your solution, don't just post. Also, try to restructure your answer on a more visually compact way. – dmitryro Jun 30 '18 at 23:48