i am required to close currently open tab in any commonly used broswer mentioned above using javascript when user click on button. i have searched a lot but could not get the correct answer. a snippet to do the above taks would be very helpfull to me. i have thoroughly gone through all the answer posted on stack overflow but none of them are working. do consider this fact will giving answer. and please it is not duplicate
Asked
Active
Viewed 904 times
0
-
Not working in FF & Chrome hence it is not duplicate. please at least check before you post comments – user3819360 Sep 21 '14 at 15:20
-
The onus is on you to respond to suggestions of duplicates, and explain why they aren't applicable. That said, in cases of ridiculous error other users will likely also respond to that suggestion. – David Thomas Sep 21 '14 at 15:50
-
1@user3819360: Even if a few of the answers there don't work any more, the question is still exactly the same. – Bergi Sep 21 '14 at 15:52
2 Answers
1
You can't close the current browser tab with javascript. It would be annoying for the user if sites start to close themselves like this without the user intent so browsers simply do not allow this.
I think you can only close a tab that was opened using Javascript. like:
function openWin() {
myWindow = window.open("", "myWindow", "width=200, height=100");
// Opens a new window
}
function closeWin() {
myWindow.close(); // Closes the new window
}

Amar1989
- 502
- 1
- 3
- 17
0
You can use window.close();
<html>
<script type="text/javascript">
function closeTab(){
window.close();
}
</script>
<body>
<div onclick="closeTab();">Close window</div>
</body>
</html>

Viktor Mezhenskyi
- 223
- 3
- 10
-
this script is not working at all in FF AND chrome latest version. – user3819360 Sep 21 '14 at 15:38