I want to block user to open new tab, close tab or browser window for 30 sec when user is on my home page in jquery, javascript. Kindly suggest.
Asked
Active
Viewed 143 times
-8
-
I don't think you're allowed to do that. – Barmar Jan 02 '15 at 09:14
-
2You have no power to prevent user to close its own browser window. – Damjan Pavlica Jan 02 '15 at 09:17
-
1sounds spammy. If you legitimate reasons, you can ask the user if he/she really wishes to close the window. read more here http://stackoverflow.com/questions/1565304/jquery-prevent-window-closing – maskie Jan 02 '15 at 09:17
-
why do you want to do that? Never make any site so user unfriendly.. So avoid that..., – annam priyatam Jan 02 '15 at 09:17
-
You shouldn't do that. – Debug Diva Jan 02 '15 at 09:18
-
Are you making a porn website? – Ashesh Jan 02 '15 at 09:29
1 Answers
5
Answer 1: You can't do that. Browsers quite correctly don't let you. You can ask the browser to show a message when the user tries to close the tab/window, details in this answer, but the browser gives the user the option to go ahead and do it anyway.
Answer 2: You shouldn't do that. You have no right to trap a user on your page — not for one second, much less 30 seconds.

Community
- 1
- 1

T.J. Crowder
- 1,031,962
- 187
- 1,923
- 1,875