Jump to content

Window closing event


karthiseenu

Recommended Posts

I can think of a possible way, when there is a parent window behind :)Just construct with javascript a condition that checks if the name of the window we're talking about, exists or not :) For all I know, there is not an onclose attribute or something :)

Link to comment
Share on other sites

Hai Dan i did that with out any parent window

This code works only in Internet Explore but not in Netscape
<html>	<head>  <script>  	var flag=0;  	function onClosing(){    if(flag == 1)    {    	alert("Refreshed");	    	flag = 0;    }    else    {    	alert("Closed");    }  	}  	  	function onPreClosing(){    flag = 1;  	}  </script>	</head>	<body onDeactivate="onPreClosing()" onUnload="onClosing();">  	</body></html>

Link to comment
Share on other sites

Hai the above solution is not working while i am post to the same page it is important because i am working with jsf.I try the following accordind to dan replyParent

<html>	<head>		<script>			var child;			function childOpen(){				child = window.open("ClosingChild.html");			}			function chkChild(){				alert(child.closed);			}		</script>	</head>	<body>		<input type="button" onClick="childOpen();" value="Click">	</body></html>

Child

<html>	<head>		<script>			var flag=0;			function onClosing(){				if(flag == 1)				{					alert("Refreshed");						flag = 0;				}				else				{					alert("Closed");					var parent = window.opener;					alert(parent);					parent.chkChild();				}							}						function onPreClosing(){				flag = 1;			}		</script>	</head>	<body onDeactivate="onPreClosing()" onUnload="onClosing();">		<a onClick="window.navigate('ClosingChild.html?name=karthi');" style="cursor:hand">Same Page</a>	</body></html>

Link to comment
Share on other sites

There is no possibility (I know of) to fetch a certain window, but there is a posibility to open a new document in a certain existing window (by loading it in the window that listens to the defined name). Because window is the upmost object, there is no way (again, that I know of) to fetch an adjacent window because there is no parent to compare it to.May I ask for what do you need this? Then we can think of other sollutions if this one cannot be. :)

Link to comment
Share on other sites

Thanku for ur reply. I am working in Java Server Faces in that every event like clicking a button post some value to the same page. I have to do some operation when closing that window. If there is any way to disable the window close button it is also helpfull for me.

Link to comment
Share on other sites

Thanku for ur reply.    I am working in Java Server Faces in that every event like clicking a button post some value to the same page. I have to do some operation when closing that window. If there is any way to disable the window close button it is also helpfull for me.

karthiseenu,If you are talking about the 'x' mark closing of the window, then you should use onbeforeUnload event.Refresh of a page is equivalent to unload and load of the page. Hence your conditions inside the onunload event will be triggered when the refresh is done.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...