944,068 Members | Top Members by Rank

Ad:
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Jul 14th, 2008
0

Re: Detect browser window closing event in Firefox -

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.
Reputation Points: 120
Solved Threads: 61
Posting Pro
Troy III is offline Offline
511 posts
since Jun 2008
Nov 26th, 2008
0

Re: Detect browser window closing event in Firefox -

but wat is the solution
Reputation Points: 15
Solved Threads: 21
Posting Whiz in Training
nikesh.yadav is offline Offline
219 posts
since Feb 2008
Nov 28th, 2008
0

Re: Detect browser window closing event in Firefox -

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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
kevinXu is offline Offline
2 posts
since Nov 2008
Nov 28th, 2008
0

Re: Detect browser window closing event in Firefox -

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...
Reputation Points: 21
Solved Threads: 26
Posting Whiz in Training
Rhyan is offline Offline
240 posts
since Oct 2006
Nov 3rd, 2009
0

Browser Close Warning Issue

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:

=====================
html Syntax (Toggle Plain Text)
  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)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ayusman.mohanty is offline Offline
4 posts
since Nov 2009
Jan 21st, 2010
0
Re: Detect browser window closing event in Firefox -
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script language=javascript>
  4.  
  5. function doSomething(e) {
  6. var posx = 0;
  7. var posy = 0;
  8. if (!e) var e = window.event;
  9.  
  10. if (e.pageX || e.pageY)
  11. {
  12. posx = e.pageX;
  13. posy = e.pageY;
  14. }
  15. else if (e.clientX || e.clientY)
  16. {
  17. posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
  18. posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
  19. }
  20. alert(posx + ", " + posy);
  21. }
  22. function confirmMe()
  23. {
  24. alert("Thank you for visiting us!!");
  25. }
  26.  
  27.  
  28. function help(e)
  29. {
  30. if (!e) var e = window.event;
  31. if (e.onclick)
  32. {
  33. document.getElementbyID("id2").style.display="block";
  34. alert("ethe");
  35. }
  36. else
  37. {
  38. document.getElementbyID("id2").style.display="none";
  39. alert("hgere");
  40. }
  41.  
  42.  
  43.  
  44. }
  45. </script>
  46. </head>
  47. <body onunload="confirmMe();">
  48.  
  49. <div onclick="doSomething(event);">Hello there</div>
  50.  
  51. <table border =2>
  52. <tr id='Id1'>
  53. <Td><input type=button name="Test" Value="Test" onclick="javascript:help(event);"> </td>
  54. </tr>
  55.  
  56. <tr id='id2' style="display:none">
  57. <td><input type="text" id="text1" value="">
  58. </td>
  59. </tr>
  60. </table>
  61.  
  62. </body>
  63. </html>
Last edited by nav33n; Jan 21st, 2010 at 7:58 am. Reason: Please use [code] tags to wrap your code for easy readability.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
govind11 is offline Offline
2 posts
since Jan 2010
Jan 21st, 2010
1

Reply to thread 'Detect browser window closing event in Firefox -'

Hi Govind - This is how it should not work...You might have misunderstood the requirement...

Click to Expand / Collapse  Quote originally posted by govind11 ...
<html>
<head>
<script language=javascript>

function doSomething(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;

if (e.pageX || e.pageY)
{
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY)
{
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
alert(posx + ", " + posy);
}
function confirmMe()
{
alert("Thank you for visiting us!!");
}


function help(e)
{
if (!e) var e = window.event;
if (e.onclick)
{
document.getElementbyID("id2").style.display="block";
alert("ethe");
}
else
{
document.getElementbyID("id2").style.display="none";
alert("hgere");
}



}
</script>
</head>
<body onunload="confirmMe();">

<div onclick="doSomething(event);">Hello there</div>

<table border =2>
<tr id='Id1'>
<Td><input type=button name="Test" Value="Test" onclick="javascript:help(event);"> </td>
</tr>

<tr id='id2' style="display:none">
<td><input type="text" id="text1" value="">
</td>
</tr>
</table>

</body>
</html>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ayusman.mohanty is offline Offline
4 posts
since Nov 2009
Jan 21st, 2010
0
Re: Detect browser window closing event in Firefox -
window event srcelement in firefox hw we use this ???
Reputation Points: 10
Solved Threads: 0
Newbie Poster
govind11 is offline Offline
2 posts
since Jan 2010
Jun 11th, 2010
0
Re: Detect browser window closing event in Firefox -
hi Deepthi,

I have also same problem. If you got answer please post on the same link.
please help me.


thanks
Satish
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ssnaphade is offline Offline
2 posts
since Jun 2010
Mar 18th, 2011
0

How to detect the browser close in Javascript.

Hi,

I want to delete a row in DB when browser is closed.
I tried onunload and onbeforeunload but they are called everytime when I navigate from one JSP page to another JSP page and also if I refresh the page.

My requirement is to call that function only when the browser is closed.

Please help ASAP

Thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Punitha Roopa is offline Offline
1 posts
since Mar 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Simple AJAX PHP game help.
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: where to put ajax file in codeigniter directory?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC