Close Current Tab
I have a close link on my web page. I would like to function it to close the current tab when click it. I have written
The above code seems to be working well in Internet Explorer. But it is not working in Mozilla Firefox and Google Chrome. Please help me to resolve this.
You can only close windows/tabs that you create yourself. That is, you cannot programmatically close a window/tab that the user creates.
For example, if you create a window with
window.open() you can close it with
As of Chrome 46, a simple
onclick=window.close() does the trick. This only closes the tab, and not the entire browser, if multiple tabs are opened.
How to close current tab in a browser window?, Close the current tab, Hold Command and press W. Reopen last tab closed, Hold Command and Shift, then press T. View next tab, Hold Press Ctrl + W (Windows) or ⌘ Command + W (Mac) on your computer's keyboard to close the tab you're currently using. Make sure you're on the tab that you want to close before doing this. 3 Close all tabs in a browser.
In a HTML you can use below code
I have tried this in Chrome 61 and IE11 it is working fine. But this is not working with Firefox 57. In Firefox we can only close, windows which opened using below command.
The 33 Most Useful Keyboard Shortcuts for Google Chrome, Note: A current window/tab will only get closed if and only if it was created & opened by that script.Means the window.close syntax is only allowed for the window/ Open a new tab: Hold Command and press T: Close the current tab: Hold Command and press W: Reopen last tab closed: Hold Command and Shift, then press T: View next tab: Hold Command and Option, then press the right arrow key: View previous tab: Hold Command and Option, then press the left arrow key: Jump to a specific tab: Hold Command and
TLDR: tricks the browser into believing JavaScirpt opened the current tab/window
window.open('', '_parent', '').close();
So for completeness
<input type="button" name="close" value="close" onclick="window.close();">
Though let it also be noted that readers may want to place this into a function that fingerprints which browsers require such trickery, because Firefox 59 doesn't work with the above.
<script> var myWindow = window.open("ANYURL", "MyWindowName", "width=700,height=700"); this.window.close(); </script>
How to close current tab in a browser window?, This shortcut saves you from needing to click the little X to close a tab. Instead, use Command-W to close your current tab. Likewise, instead of I have an ASP.NET MVC app that opens a "Request" view in a new browser window. When the user submits the form, I'd like the window to close. What should my RequestController code look like to close
21 Chrome shortcuts you need to know, open() method. Now suppose you want to create a link that will close the current tab when it will be clicked. To do that lets first create our HTML link