-2

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.

Fuad Hasan
  • 3
  • 1
  • 5

2 Answers2

-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.

-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