Reputation: 225
Is there any easy work around to close the current tab and open a new tab by javascript?
Upvotes: 7
Views: 21305
Reputation: 5195
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
Upvotes: 5
Reputation: 21
var win = window.open('/Employees/GetAttendenceDataBySelectedData/?attendDateString=' + $("#AttendDate").val() + ', "_blank');
window.top.close();
Upvotes: 1
Reputation: 129
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
http://www.irt.org/script/311.htm
Upvotes: 1
Reputation: 2248
Try below :
window.open('http://www.google.com','_blank');window.setTimeout(function(){this.close();},1000)
Upvotes: 5