Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Browser Close(x) Button

Status
Not open for further replies.

venomdesign

Programmer
Apr 6, 2001
18
US
Is there a way to disable the close (x) button in netscape and IE, so until an action has been accomplished by the user in the window the window can not be closed.
 
No, there isn't.

I'm fairly sure that's a security issue that the browsers address. Think about it -- you go to a site with a bunch of popups, and they all have the close buttons disabled???

While it might be useful every once in a blue moon, it's a very good thing that there isn't a way to do it.

:)
 
Although there is no way to disable to close (x) button directly, it can be achieved by a function in IE4+.

In the onload event of the window you call a function which has this text in it:
this.window.onbeforeunload=beforeUnload; //functionality for [x] closing the window

Because it is JScript, don't put the function bracets after the 'beforeUnload' call.

You also have to make a function called "beforeUnload" where you do your check like so:
function beforeUnload() {
return "Are you sure you want to quit?";
}

Now an alert with this text is shown. When you press OK, the window will close, otherwise it will remain opened.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top