karthiseenu Posted May 26, 2006 Share Posted May 26, 2006 Hai friends, I want to capture the window closing event. I tried the onUnload event but it also fired on document refresh. I wants to capture only window closing. can any one lead me to do this Link to comment Share on other sites More sharing options...
Jack McKalling Posted May 26, 2006 Share Posted May 26, 2006 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 More sharing options...
karthiseenu Posted May 26, 2006 Author Share Posted May 26, 2006 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 More sharing options...
karthiseenu Posted May 30, 2006 Author Share Posted May 30, 2006 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 More sharing options...
Jack McKalling Posted May 30, 2006 Share Posted May 30, 2006 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 More sharing options...
karthiseenu Posted May 31, 2006 Author Share Posted May 31, 2006 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 More sharing options...
malcolm Posted May 31, 2006 Share Posted May 31, 2006 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.<{POST_SNAPBACK}> 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 More sharing options...
Jack McKalling Posted May 31, 2006 Share Posted May 31, 2006 But remember this onbeforeunload event may not work in other than IE, its not standard, so visitors of other browsers would just be able to get round the event Link to comment Share on other sites More sharing options...
karthiseenu Posted June 1, 2006 Author Share Posted June 1, 2006 Thanku My application is only works on internet explorer Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now