Reputation: 123
I want to use a button in a desktop app that will close the current browser tab. the script works fine if I have opened that page for the first time, but isn't working I use it in a second page.
Example: I open a new tab with the homepage. Then, from there, I navigate on another page where there's the exit button. Here i want the people to be able to exit but they can't. Esle, if I open directly the second page the button works fine closing the tab correctly.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="javascript:closeWindow();">Close Window</a>
<script>
function closeWindow() {
window.open('','_parent','');
window.close();
}
</script>
anyone knows hot to fix it?
Upvotes: 0
Views: 545
Reputation: 315
Hope this will help:
function closeWindow() {
window.open('', '_blank');
window.close();
}
<button onclick="closeWindow()"> Close</div>
<script src="js.js"></script>
Upvotes: 1