wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes How to disable the close(cross) button of a window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to disable the close(cross) button of a window" Watch "How to disable the close(cross) button of a window" New topic
Author

How to disable the close(cross) button of a window

Gaurav Goyal
Greenhorn

Joined: Apr 25, 2006
Posts: 6
I am opening a window using window.open. I want to disable the close(cross)(X) button which appears on the right hand top corner of the window.
I tried
window.open(popurl,"","width=1000,height=700,titlebar=0,top=5,left=5,screenX=100,screenY=100");
and
window.open(popurl,"","width=1000,height=700,titlebar='NO',top=5,left=5,screenX=100,screenY=100");
but none works as desired.
In the specs at w3schools.com I found

===========================================================================
titlebar = yes | no | 1 | 0
whether to display the title bar. Ignored unless the calling application is an HTML Application or a trusted dialog box. Default is yes
===========================================================================

I am calling this from a JSP of the same application.
Please help. Thanks in Advance.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You can't.
You don't own the user's desktop and shouldn't try to prevent the user from managing his/her own windows.
Webapps need to be written with the assumption that the user could leave at any time.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Gaurav Goyal
Greenhorn

Joined: Apr 25, 2006
Posts: 6
Alright. So is there any particular event which specifically gets called only when the close(cross)(X) button is clicked.
The onUnload event gets called on the click of this button but is also called when the form is submitted(rather than a solution this becomes a problem).
Debashree Halder
Ranch Hand

Joined: Jul 27, 2005
Posts: 81
Check out this piece of code: It resizes the window to full screen. Hence you will not get any cross button



Debashree Halder<br />SCJP 1.5<br />Washington DC
vaibhav anubhav
Greenhorn

Joined: Mar 24, 2006
Posts: 5
You can do one thing. When any user close you window, a new window will open, that will content same thing.
Gaurav Goyal
Greenhorn

Joined: Apr 25, 2006
Posts: 6
Thanks Debashree this works & solves my purpose. But wanted to know the purpose of || w.resizeTo ( 300, 200 ); || here, as its presence or absence or a diff set of arguments is not affecting the output. Pls correct me if I am wrong, I guess it is not working as we have already set the resizable property of window as 'no'.
My purpose is solved but would be thankful if someone can tell about the specific event which is called on the click of close(cross)(X) button.
Debashree Halder
Ranch Hand

Joined: Jul 27, 2005
Posts: 81
It was part of the whole code...u can neglect that. No probs....
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by vaibhav anubhav:
You can do one thing. When any user close you window, a new window will open, that will content same thing.


That is an obnoxious thing to do.
Most people, upon encountering this irritating behaviour, will immediately dismiss your app as a low grade, poorly written, and possibly dangerous site.

Also most browsers offer protection from popups instanciated from onLoad or onUnload function calls.

In any case none of this has anything to do with JSP so I'm going to move the thread to HTML/Javascript.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Originally posted by Debashree Halder:
Check out this piece of code: It resizes the window to full screen. Hence you will not get any cross button



Um, if that works on your computer, you really need to download a service pack. That bug has been fixed for years.

Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You are not going to be able to do it. Why are you doing this in the first place. Use an iframe dynamiclaly poisitioned over the content on the page. No need for a pop up window, no close button issue, etc.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Originally posted by Ben Souther:

That is an obnoxious thing to do.


It sure it! The first time a web site does this to me, will be the last!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rusty Smythe
Ranch Hand

Joined: Aug 09, 2006
Posts: 93
Originally posted by Ben Souther:
Most people, upon encountering this irritating behaviour, will immediately dismiss your app as a low grade, poorly written, and possibly dangerous site.


If I had to use that app (maybe because of work), then I'd solve that irritating problem once and for all by applying a liberal dose of GreaseMonkey.

As others have pointed out, there is no way to control anything on a user's computer. HTML code is nothing more than SUGGESTIONS to the user's browser. Knowing this is what seperates the script kiddies from professional web developers.
Gaurav Goyal
Greenhorn

Joined: Apr 25, 2006
Posts: 6
The iframe will not help with that. This really is a job for user training if it is in in house application and session end on the server.

Eric
[ August 18, 2006: Message edited by: Eric Pascarello ]
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I had a very similar situation. I ended up using XmlHttpRequest to ping the server periodically, so the server could tell my window was still open. When the server stops receiving pings, it knows it can clean up.

If the user presses *our* Close button, the clean up happens straight away. If they press the *browser's* Close button, the clean up has to wait for a time-out. As ours is an intranet Web application, we don't have to make the time-out terribly long. On a true internet Web application, the time-out would have to be quite long, to allow for rubbish connections etc.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to disable the close(cross) button of a window
 
Similar Threads
issue with opener in JavaScript
window.open screenX is un-cooperative
How can I put progress bar in my child window?
Window Sizing
Submit a form via hyperlink