How we can control the browser window with out closing while clicking on close(X) button
of the window.
How we can control the browser window with out closing while clicking on close(X) button
of the window.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
RakrusPosted Dec 4, 2007, 12:26 AM
Hi Deepak,
Yeah,in unload we can ask a confirmation,but i don't want any confirmations.While clicking on window's X it has to keep quite.
Thanks
Rakesh
dk_deepak008Posted Nov 29, 2007, 4:51 AM
Let's say you want to trap the window close event for the web browser so that you can give a confirmation dialog asking if the user is sure to leave the page. The problem is that there is no onclose event for the window object. The closest event might be onunload since it fires immediately before the window object is unloaded. However, when the onunload event fires it is too late to display a JavaScript alert. Therefore, we need an event that fires prior to a page being unloaded, which is onbeforeunload. Define onbeforeunload event in your page <BODY> element as follows:
<BODY onbeforeunload="HandleOnClose()">
Then, add the following JavaScript code into the <HEAD> section of your ASPX page:
<script language="javascript">
script>
The trick here is to check clientY property of the event object, which is used to set or retrieve the y-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars. This way, you can detect if the user clicked on X button to close the page, or clicked on Refresh button to refresh the page, etc. This approach does not handle key events such as Alt-F4 that lets the user close the window by using the keyboard.