Detect browser window closing event in Firefox -

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Jun 2008
Posts: 348
Reputation: Troy III will become famous soon enough Troy III will become famous soon enough 
Solved Threads: 42
Troy III's Avatar
Troy III Troy III is offline Offline
Posting Whiz

Re: Detect browser window closing event in Firefox -

 
0
  #21
Jul 14th, 2008
I think that "load/unload" the document is the only appropriate notion to use in situations when:
1. user is closing the current page [ap dependable op] currently associated with ap. close;
2. the user is loading [as a final step of download, cache, parse, render procedure] a New Page in the same docked browser window (called browser tab while in fact being just another instance of an independent dock-able browser window), causing the previous page to be unloaded from active memory and free the space previously taken by its content.
3. Moving back and forth the browser history, inside the same tab/docked window, should be considered as load/unload process, -moreover, this action should factually cause the page to get "loaded/unloaded" from active memory, snce it already exists in a browser cache and there is absolutely no practical reason to leave it "eat" your system resources as last generation browsers do.

This undoubtedly means that: if the user closed the page he was on (although I don't know if there is such browser providing that option), opened another page in the same window/browser tab, navigated back and forth, should all actually carry out the task, to unload/load content, while, same time triggering corresponding events. But I think that browser close should be discerned from document close which is an equivalent of page unload, but this two different actions/events have in practice, the same meaning for the page content therefore right now it is unnecessary to discern. Although browser close and /or tab close comparing to page close/unload, should have different meanings on the browser domain, wihch I believe are already differentiated.
*
But it's a completely different story when (ctrl) tabbing or alt+tabbing between browser windows containing data. This doesn't fall in navigating category. In this case: only the screen display gets redrawn, but nothing else. No events should fire nor any other action be carried out except window/tab focus with any other focus event aliases. Meaning, only the conventional (focus/blur) events should fire. Smart browsers will during this event (focus) check if any content changes have occurred on the side of source provider and update if specified or some other way required.

Generally speaking There's nothing more efficient than loading pages from browser cache. Keeping them in memory causes what f.i. firefox users are complaining the most: memory leaks.

Regards.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 213
Reputation: nikesh.yadav is an unknown quantity at this point 
Solved Threads: 17
nikesh.yadav's Avatar
nikesh.yadav nikesh.yadav is offline Offline
Posting Whiz in Training

Re: Detect browser window closing event in Firefox -

 
0
  #22
Nov 26th, 2008
but wat is the solution
Help as an alias

I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: kevinXu is an unknown quantity at this point 
Solved Threads: 1
kevinXu kevinXu is offline Offline
Newbie Poster

Re: Detect browser window closing event in Firefox -

 
0
  #23
Nov 28th, 2008
Seems my solution is better.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1.  
  2. <head>
  3. <script>
  4. var jmp=false;
  5. function jmp(){
  6. if(jmp){
  7. location.href='ExecCmd?exitClr=1';
  8. }
  9. }
  10. </script>
  11. </head>
  12. <body onload="change();" onunload="jmp();">
  13. </body>

Set the jmp to define jump or not.
It works fine in IE but partially in Firefox.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 232
Reputation: Rhyan is an unknown quantity at this point 
Solved Threads: 24
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Posting Whiz in Training

Re: Detect browser window closing event in Firefox -

 
0
  #24
Nov 28th, 2008
Ok, guys, why do we need such a word fight for nothing?

Actually I did not understand what is exactly the requirement - I mean, does the guy want to have the code work in any browser window on closing it, or he just wants to do something upon closing a specific window only.

If he needs to do something only in a specific window, he can call the specific window using window.open() - just like a popup.... Then the window.close() method will close only this specific window.
As the window.close() can be called within another function, the guy can just create a new closing function, linked on a specific close button.
So it looks like
function myclosingfx()
{
do whatever i want to do;
if (doing this successful)
{
window.close();
}
}
Then just put a button on top of the page - close me with action onclick="myclosingfx()"

And that's that.

Unfortunately as far as I know onunload cannot distinguish between navigating to another page or simply closing the window, so I think it cannot be used in this case. So I don't have a solution for let's say - any browser window...just for the popus...
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: ayusman.mohanty is an unknown quantity at this point 
Solved Threads: 0
ayusman.mohanty ayusman.mohanty is offline Offline
Newbie Poster

Browser Close Warning Issue

 
0
  #25
Nov 3rd, 2009
Hi,
Even I am trying the browser close event for cross browser and this should trigger only when X button is clicked or page is refreshed. Here's the code I am using but it only works in IE:

=====================
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><head>
  2. <title>Warning Test</title>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <meta http-equiv="Content-Style-Type" content="text/css">
  5. <meta http-equiv="Content-Script-Type" content="text/javascript">
  6. <script language="JavaScript">
  7.  
  8. // warning message javascript
  9.  
  10. var isOpera, isIE, isNav, isFox, isOther = false;
  11. if (navigator.userAgent.indexOf("Opera") != -1) {
  12. isOpera = true;
  13. } else if (navigator.userAgent.indexOf("Firefox") != -1) {
  14. isFox = true;
  15. } else if (navigator.appName == "Microsoft Internet Explorer") {
  16. isIE = true;
  17. } else if (navigator.appName == "Netscape") {
  18. isNav = true;
  19. } else {
  20. isOther = true;
  21. }
  22.  
  23. if (isIE || isOpera || isNav || isFox || isOther) {
  24. window.onbeforeunload = WarnUser;
  25. function WarnUser() {
  26. OffsetX = window.event.clientX;
  27. OffsetY = window.event.clientY;
  28. if (((window.event.clientX < 0) || (window.event.clientY < 0))
  29. && (isWarnUser == true)) {
  30. event.returnValue = " ";
  31. //window. önunload = sessionInvalidate;
  32. } else {
  33. // Reset the flag to its default value.
  34. isWarnUser = true;
  35. }
  36. }
  37. }
  38.  
  39.  
  40.  
  41.  
  42. </script>
  43.  
  44. </head>
  45. <body>
  46. <script type="text/javascript">
  47. var isWarnUser = true;
  48. </script>
  49. test
  50. </body>
  51. </html>
========================

I know the issue is because of window.events and ClientX/ClientY.
Could someone please fix my code to make it work in all browsers? This is very urgent and have been striving since 3 days...

*Please Note: Current code is working in IE only and to check you have to close the browser window or refresh the page with mouse click.
Last edited by peter_budo; Nov 5th, 2009 at 6:58 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC