From: Stefan Weiss on
On 18/02/10 18:42, Jayesh Modha wrote:
> Unfortunately, I don't have a public page.
>
> I totally forgot CTRL + R, wow, thanks a lot for that. I will include
> that into my code.
> Hopefully, I haven't forgot any of my code here but I will zip up my
> code and send to you if you'd prefer that.

I'm curious about what you're trying to accomplish. I see how it can be
useful to issue a warning when a document is about to be unloaded (for
example, if there are unsaved changes, or the user is in the middle of a
chess game with a live opponent), but why do you want to detect the
difference between closing a window and reloading a document? That
sounds like a reload could lead to an undesired state, and from my
experience, those cases are better handled on the server side.

Whatever the goal is, I doubt you can reliably detect a reload if you're
relying on clicks and keyboard events.


(PS, please don't top-post on Usenet)

--
stefan
From: David Mark on
Stefan Weiss wrote:
> On 18/02/10 18:42, Jayesh Modha wrote:
>> Unfortunately, I don't have a public page.
>>
>> I totally forgot CTRL + R, wow, thanks a lot for that. I will include
>> that into my code.
>> Hopefully, I haven't forgot any of my code here but I will zip up my
>> code and send to you if you'd prefer that.
>
> I'm curious about what you're trying to accomplish. I see how it can be
> useful to issue a warning when a document is about to be unloaded (for
> example, if there are unsaved changes, or the user is in the middle of a
> chess game with a live opponent), but why do you want to detect the
> difference between closing a window and reloading a document? That
> sounds like a reload could lead to an undesired state, and from my
> experience, those cases are better handled on the server side.
>
> Whatever the goal is, I doubt you can reliably detect a reload if you're
> relying on clicks and keyboard events.

There is no doubt that it can't be done. Any design hinging on doing
that is doomed at the start.

>
>
> (PS, please don't top-post on Usenet)
>

Seconded. :)
From: rf on

"Stefan Weiss" <krewecherl(a)gmail.com> wrote in message
news:f-6dnRESH5CwV-DWnZ2dnUVZ7oKdnZ2d(a)giganews.com...
> On 18/02/10 18:42, Jayesh Modha wrote:
>> Unfortunately, I don't have a public page.
>>
>> I totally forgot CTRL + R, wow, thanks a lot for that. I will include
>> that into my code.
>> Hopefully, I haven't forgot any of my code here but I will zip up my
>> code and send to you if you'd prefer that.
>
> I'm curious about what you're trying to accomplish. I see how it can be
> useful to issue a warning when a document is about to be unloaded (for
> example, if there are unsaved changes, or the user is in the middle of a
> chess game with a live opponent), but why do you want to detect the
> difference between closing a window and reloading a document? That
> sounds like a reload could lead to an undesired state, and from my
> experience, those cases are better handled on the server side.

I'll bet the OP has a form on the page that the OP does not want
re-submitted.

> Whatever the goal is, I doubt you can reliably detect a reload if you're
> relying on clicks and keyboard events.

Indeed.


From: Jayesh Modha on
On Feb 18, 4:25 pm, "rf" <r...(a)z.invalid> wrote:
> "Stefan Weiss" <krewech...(a)gmail.com> wrote in message
>
> news:f-6dnRESH5CwV-DWnZ2dnUVZ7oKdnZ2d(a)giganews.com...
>
> > On 18/02/10 18:42, Jayesh Modha wrote:
> >> Unfortunately, I don't have a public page.
>
> >> I totally forgot CTRL + R, wow, thanks a lot for that. I will include
> >> that into my code.
> >> Hopefully, I haven't forgot any of my code here but I will zip up my
> >> code and send to you if you'd prefer that.
>
> > I'm curious about what you're trying to accomplish. I see how it can be
> > useful to issue a warning when a document is about to be unloaded (for
> > example, if there are unsaved changes, or the user is in the middle of a
> > chess game with a live opponent), but why do you want to detect the
> > difference between closing a window and reloading a document? That
> > sounds like a reload could lead to an undesired state, and from my
> > experience, those cases are better handled on the server side.
>
> I'll bet the OP has a form on the page that the OP does not want
> re-submitted.
>
> > Whatever the goal is, I doubt you can reliably detect a reload if you're
> > relying on clicks and keyboard events.
>
> Indeed.

Thank you all JavaScript gurus for presenting your views. I am trying
to detect most common methods of refreshing the window relating to my
application, those are F5, CTRL+F5 and right click refresh. I just to
give warning message on detection.

In my case, there are no unsaved data but I definitely don't want to
submit the form again. Please don't be rigid that it cannot be done.
Please look at my code, try to understand it.
My application is in pop up window so there are no standard browser
buttons to do any activities like refresh/stop etc....
Here's the logic of what I am doing in the code.

1. Keyboard refresh
I have flag called tryingToReload.
I set this flag when some presses F5, CTRL + F5, CTRL + R.
When I get to onbeforeunload event, I check if I have flag set, if the
flag is set, user has requested refresh. I want to present them a
warning that if you refresh, you will lose activities of current
session.
I reset tryingToReload when you click anywhere or any other activities
detected.

2. Mouse refresh
I am using the same flag
I set this flag when some presses right click on form and tag is
either Body,TD or Div (those are only possible tags on my forms whose
right click would present refresh option). So most likely you are
going to refresh after opening context menu. if you don't select
refresh and do any other activity, I am resetting the flag.
If you select refresh option, onbeforeunload event would have flag
set, so it means you were trying to refresh and by detecting this, I
present the user a warning message.

This work fine with all the browsers. Here's the real problem I have.

When you do a right click but don't select refresh (remember my flag
is set because you clicked on Body, TD or Div) and now you close
window either by X close button on title bar or right click on title
bar and select close from context menu (my app is in pop up window
without standard browser buttons so there are no other options to
chose), as my flag is set now, I am going to present warning which is
wrong as the user is not refreshing the window, he is closing and I
shouldn't present this warning on close.

Again I don't have this issue with IE browser as IE would give me the
mouse click location (e.clientY) even if it is on the title bar so the
solution works fine for IE but other browser don't give me the mouse
location on onbeforeunload event so that is the issue. But this edge
to edge case for my application.

Thanks,
Jayesh Modha