You cannot disable the user from closing the window but you can do this which will prompt them with a message before closing
<body onbeforeunload="event.retu
Main Topics
Browse All TopicsI have an application to require user to stay with the current browser window. So I need to find way to disable "alt + tab" so that the user can't switch from the current browser window to another browser window. Also I need to find way to stop users to close the browser in any way. Can I do this? Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here's a method for control function keys being used. It will know if you have a function key such as alt, shift, ctrl etc.. pressed or not pressed and also what key you used in combination with it.
var SHIFT_KEY = 16;
var CTRL_KEY = 17;
var ALT_KEY = 18;
var SHIFT_DOWN = false;
var CTRL_DOWN = false;
var ALT_DOWN = false;
function editKeyUp(evt) {
evt = (evt) ? evt : window.event
var keyCode = evt.keyCode;
if ( keyCode == SHIFT_KEY )
SHIFT_DOWN = false;
if ( keyCode == CTRL_KEY )
CTRL_DOWN = false;
if ( keyCode == ALT_KEY )
ALT_DOWN = false;
}
function editKeyDown(evt) {
evt = (evt) ? evt : window.event;
var keyCode = evt.keyCode;
if ( keyCode == SHIFT_KEY )
SHIFT_DOWN = true;
if ( keyCode == CTRL_KEY )
CTRL_DOWN = true;
if ( keyCode == ALT_KEY )
ALT_DOWN = true;
}
<body onkeydown="editKeyDown()" onkeyup="editKeyUp()">
sorry just found out that the browser doenst generate a keypress event for tab and alt
<html>
<head>
<script language="javascript">
// --------------------------
// Name: DisableKeys( )
// Abstract: Disable the alt key and the enter key
// --------------------------
function DisableKeys( )
{
alert( window.event.keyCode );
if (window.event.keyCode == 9 ) window.event.keyCode = 0;
}
</script>
</head>
<body onkeypress="DisableKeys()"
</body>
</html>
you have to open a pop up window from your the main window somehow
either
<body onload="ShowModalDialog()"
function ShowModalDialog()
{
window.showModalDialog( "NameOfPage.html", "Arguments you want the window to have", "Options you want the window to have (like height, width, scrollbars)" );
}
http://support.microsoft.c
I just copy & paste justinbillig's code from <html> to </html> without changing anything. Then save as test.html. I then open test.html, I could press alt+tab to switch window. Also I do dgelinas as:
<html>
<head>
<script language="javascript">
var SHIFT_KEY = 16;
var CTRL_KEY = 17;
var ALT_KEY = 18;
var SHIFT_DOWN = false;
var CTRL_DOWN = false;
var ALT_DOWN = false;
function editKeyUp(evt) {
evt = (evt) ? evt : window.event
var keyCode = evt.keyCode;
if ( keyCode == SHIFT_KEY )
SHIFT_DOWN = false;
if ( keyCode == CTRL_KEY )
CTRL_DOWN = false;
if ( keyCode == ALT_KEY )
ALT_DOWN = false;
}
function editKeyDown(evt) {
evt = (evt) ? evt : window.event;
var keyCode = evt.keyCode;
if ( keyCode == SHIFT_KEY )
SHIFT_DOWN = true;
if ( keyCode == CTRL_KEY )
CTRL_DOWN = true;
if ( keyCode == ALT_KEY )
ALT_DOWN = true;
}
</script>
</head>
<body onkeydown="editKeyDown()" onkeyup="editKeyUp()">
Test dgelinas's code
</body>
</html>
Thanks.
So there is no way to force my user to stay a window until I let them go? I already opened a window withouting toobar, statusbar, addressbar. Actually the window only has minimum icon, maximum icon and close icon on the top left. I also capture mouse right click event so that I will give a warning whenever the use right-click the mouse. If I can capture the alt/tab event and close event, I will be there. Thanks.
Is there any rule that we have to answer the last comment? Usually I might walk away if I think that this is not my answer. I am not sure that I have to keep answering unless It has something to my answer. I thought that the only way to accept answer were to accept answer, but not default as not answering last comment. If it is a rule I learnt today, I buy it.
http29,
Experts volunteer their time on the site and the least the Askers can do is to answer them.
Here - I see a valid answer. And you say it is not. Please explain why the last suggestion does not help you.
And yes - if you read the help page you will see that anyone can get their points back only if they answer to every singlke experts comment.
>>I am not sure that I have to keep answering unless It has something to my answer.
And you probably think that experts are mindreaders and they know that the last thing posted is not your answer? Well... they are not. They are just people trying to help you. And you should answer them... until they post. Because tehy try to help you.
You may request deletion of the question if you had not received your answer. But as I said : For me this quetsions is answered (it is all another story if you do not like the answer). If you still think it is not answered - POST YOUR REASONS! Thank you :)
Business Accounts
Answer for Membership
by: justinbilligPosted on 2004-06-02 at 11:40:52ID: 11215494
not the main window they open up, you might be able to disable alt tab with the onkeypress event in the body
if windows.event.keypress == ( whatever the ascii value of alt is )
{
windows.event.keypress = 0;
}
do the same for tab also
but if you really want the user to stay with a window you might want to use window.showmodaldialog ... that will disallow the user from accessing other elements in the browser until they finish with the current one