I want my website to be closed on a custom close div or button. That's because the page may have many previous pushShates so clicking the browsers back button will take to the previous page. So, I want when user clicks the button my website will close.
Asked
Active
Viewed 96 times
2 Answers
-1
window.close();
Should close the current tab which the user sees. It only closes the current tab though. Add this as an event to your div and when the user click on it, it would close the current window.
vincent_schuur
- 29
- 1
- 6
-
doesn't work. on the console: Scripts may close only the windows that were opened by them. – Fuad Hasan Mar 14 '22 at 07:46
-1
If you're talking about closing your current tab then you can just use the function below.
window.close();
Just use a workaround through redirecting the window to something else cause this problem is pretty self-explanatory, it doesn't allow closing window that is not opened by it through JS. There's nothing can be done so use the method below
window.location.href = 'your redirection here';
Xiel
- 1
- 2
-
no is doesn't. because the window.close() only closes windo created by itself – Fuad Hasan Mar 14 '22 at 07:18
-
dude, how about you give more context to your problem, maybe that will help – Xiel Mar 14 '22 at 07:20
-
on the console: Scripts may close only the windows that were opened by them. – Fuad Hasan Mar 14 '22 at 07:32
-
-
-
@FuadHasan There is no solution to your problem; this is a browser security issue, as is described in this answer: https://stackoverflow.com/questions/19761241/window-close-and-self-close-do-not-close-the-window-in-chrome/19768082#19768082 – Daedalus Mar 14 '22 at 08:15