469,327 Members | 1,145 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

Detecting onmouseup outside browser window?

If I perform a mousedown within a document, move the mouse outside the
browser window, and then release the mouse button, the document.onmouseup
event does not fire. Is there any way to detect a mouseup event outside the
document?

Also, how can I get the relative coordinates of the cursor while it is
outside the browser?

Thank you.
Jul 23 '05 #1
20 7436
Mandy Memphis wrote:
If I perform a mousedown within a document, move the mouse outside the
browser window, and then release the mouse button, the document.onmouseup
event does not fire. Is there any way to detect a mouseup event outside the
document?
No.
Also, how can I get the relative coordinates of the cursor while it is
outside the browser?


You can't.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #2
"Randy Webb" <hi************@aol.com> wrote in message
news:8Y********************@comcast.com...
Mandy Memphis wrote:
If I perform a mousedown within a document, move the mouse outside the
browser window, and then release the mouse button, the document.onmouseup event does not fire. Is there any way to detect a mouseup event outside the document?


No.
Also, how can I get the relative coordinates of the cursor while it is
outside the browser?


You can't.


Hi Randy,

Walter Zorn has managed it. See here:

http://www.walterzorn.com/dragdrop/dragdrop_e.htm

I just wish his code wasn't so cryptic!
Jul 23 '05 #3
On Mon, 5 Jul 2004 13:15:03 -0400, Mandy Memphis wrote:
"Randy Webb" <hi************@aol.com> wrote in message
Mandy Memphis wrote:
If I perform a mousedown within a document, move the mouse outside the
browser window, and then release the mouse button, the document.onmouseup event does not fire. Is there any way to detect a mouseup event outside the document?
No.
Also, how can I get the relative coordinates of the cursor while it is
outside the browser?


You can't.

... Walter Zorn has managed it. See here:

http://www.walterzorn.com/dragdrop/dragdrop_e.htm


You assertion does not seem to be borne out
by the way the code acts.

E.G. If you make your browser window 'little' and
put it in the middle of the screen, you can drag
the mouse out of the window on the right, the image
will keep scrolling (too the right). While the image
keeps scrolling (within the web page), you can move
the mouse pointer around the outside of the window,
when you enter it on the left, the script seems to
recognize *that* and the image which was still scrolling
right now jumps to the left of the screen.

That behaviour supports what Randy was saying,
the script is not aware of the co-ords of the
mouse when it is beyond the window.

It is a security thing AFAIU, you do not want some
script from a web-page able to monitor what you
do beyond the browser, that could allow all sorts
of nasty snooping.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #4
Andrew Thompson wrote:
Walter Zorn has managed it. See here:
http://www.walterzorn.com/dragdrop/dragdrop_e.htm You assertion does not seem to be borne out
by the way the code acts.


On the contrary, it works for me.
If I resize my browser (IE6) to the middle of the screen, I can drag
something off to the left. While my cursor is outside of the browser window
completely, I can still move the image around (and my cursor stays as a
'move' graphic). When I let go, outside of the browser window, it stops
dragging. This was the behavior that the OP was asking for, I believe.

Mandy Memphis wrote: I just wish his code wasn't so cryptic!


Me too, he has some good functions in there. But trying to reuse or alter
any of them is more work than it's worth...

--
Matt Kruse
Javascript Toolbox: http://www.JavascriptToolbox.com/
Jul 23 '05 #5
On Mon, 5 Jul 2004 14:53:12 -0500, Matt Kruse wrote:
Andrew Thompson wrote:
Walter Zorn has managed it. See here:
http://www.walterzorn.com/dragdrop/dragdrop_e.htm

You assertion does not seem to be borne out
by the way the code acts.


On the contrary, it works for me.
If I resize my browser (IE6)


Oops, my bad.. forgot to mention I tested in
Moz 1.3.. (actually I did not even notice till
you mentioned the page, I had both browsers
open at the time..)

Probably some IE security hole.. ;-)

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #6
Mandy Memphis wrote:
"Randy Webb" <hi************@aol.com> wrote in message
news:8Y********************@comcast.com...

<--snip-->
Hi Randy,

Walter Zorn has managed it. See here:
No, he has attempted to manage it. It fails, utterly, in Mozilla.
I drug the cat down, let go of the mouse outside the window, and even
while I am typing this, it is still attempting to scroll the cat down
even more.
http://www.walterzorn.com/dragdrop/dragdrop_e.htm

I just wish his code wasn't so cryptic!


When I see code like this:

href="javascript:void(0)"

I tend to stop reading anymore, as the author code such as that isn't
very aware of reality on the web.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #7
On Mon, 05 Jul 2004 19:27:08 -0400, Randy Webb wrote:
I drug the cat down, let go of the mouse outside the window,


Isn't is safe to let the mouse go inside the
window if the cat is drugged? Maybe not if
it's speed or coke though. ;-)

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #8
"Randy Webb" <hi************@aol.com> wrote in message
news:59********************@comcast.com...
Mandy Memphis wrote:
"Randy Webb" <hi************@aol.com> wrote in message
news:8Y********************@comcast.com...


<--snip-->
Hi Randy,

Walter Zorn has managed it. See here:


No, he has attempted to manage it. It fails, utterly, in Mozilla.
I drug the cat down, let go of the mouse outside the window, and even
while I am typing this, it is still attempting to scroll the cat down
even more.
http://www.walterzorn.com/dragdrop/dragdrop_e.htm

I just wish his code wasn't so cryptic!


When I see code like this:

href="javascript:void(0)"

I tend to stop reading anymore, as the author code such as that isn't
very aware of reality on the web.


He was aware enough to get something to work that you said couldn't be done!
;-P
Jul 23 '05 #9
Randy Webb wrote:
When I see code like this:
href="javascript:void(0)"
I tend to stop reading anymore, as the author code such as that isn't
very aware of reality on the web.


I don't think that's a fair statement.
Obviously, Mr. Zorn is not a newbie script kiddie, and to be so judgemental
of his abilities based on a snippet of code is a bit unwarranted, IMO.

--
Matt Kruse
Javascript Toolbox: http://www.JavascriptToolbox.com/
Jul 23 '05 #10
Mandy Memphis wrote:

<--snip-->

When I see code like this:

href="javascript:void(0)"

I tend to stop reading anymore, as the author code such as that isn't
very aware of reality on the web.

He was aware enough to get something to work that you said couldn't be done!
;-P


No, because it doesn't work.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #11
Matt Kruse wrote:
Randy Webb wrote:
When I see code like this:
href="javascript:void(0)"
I tend to stop reading anymore, as the author code such as that isn't
very aware of reality on the web.

I don't think that's a fair statement.
Obviously, Mr. Zorn is not a newbie script kiddie, and to be so judgemental
of his abilities based on a snippet of code is a bit unwarranted, IMO.


No, he is not a newbie script kiddie, but I still tend to discount code
written that has snippets of that in it. I also tend to discount code
that has attempted obfuscation in it, and thats based on his .js file.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #12
"Randy Webb" <hi************@aol.com> wrote in message
news:7o********************@comcast.com...
Mandy Memphis wrote:

<--snip-->

When I see code like this:

href="javascript:void(0)"

I tend to stop reading anymore, as the author code such as that isn't
very aware of reality on the web.

He was aware enough to get something to work that you said couldn't be done! ;-P


No, because it doesn't work.


Work for me.
Jul 23 '05 #13
On Tue, 6 Jul 2004 21:40:04 -0400, Mandy Memphis wrote:
No, because it doesn't work.


Work for me.


The natural assumption on this group is that you
are developing for the web unless otherwise stated.

On the web, it does not work. ( Note that you
have already had a 50% failure rate in the
4 tests conducted. )

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #14
Andrew Thompson wrote:
The natural assumption on this group is that you
are developing for the web unless otherwise stated.
On the web, it does not work. ( Note that you
have already had a 50% failure rate in the
4 tests conducted. )


It would be more correct to say that on the web, it does not work with all
browsers, but most likely does work for the majority of users. Also, it
appears to degrade gracefully (not causing any problems in browsers where it
doesn't work) which is exactly what we'd want.

So, in summary, it appears to be a fantastic solution, IMO.

--
Matt Kruse
Javascript Toolbox: http://www.JavascriptToolbox.com/
Jul 23 '05 #15
On Wed, 7 Jul 2004 11:14:37 -0500, Matt Kruse wrote:
..50% failure rate in the
4 tests conducted.


It would be more correct to say that on the web, it does not work with all
browsers, but most likely does work for the majority of users. Also, it
appears to degrade gracefully (not causing any problems in browsers where it
doesn't work) which is exactly what we'd want.


Doesn't have the same ring to it as..
"50% failure rate in the 4 tests conducted."
...which is an accurate statement.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #16
Andrew Thompson wrote:
Doesn't have the same ring to it as..
"50% failure rate in the 4 tests conducted."
..which is an accurate statement.


a) Flawed statistics are meaningless. "100% success rate in the browsers
used by 94% of site visitors" is another statistic which might be accurate.
b) Every single javascript every written will fail in at least one situation
c) It doesn't really matter, since the solution does exist, works nicely in
a subset of browsers, and degrades gracefully - everything js code should
do. :)

--
Matt Kruse
Javascript Toolbox: http://www.JavascriptToolbox.com/
Jul 23 '05 #17
Matt Kruse wrote:
Andrew Thompson wrote:
The natural assumption on this group is that you
are developing for the web unless otherwise stated.
On the web, it does not work. ( Note that you
have already had a 50% failure rate in the
4 tests conducted. )
It would be more correct to say that on the web, it does not work
with all browsers,


Surly it does not work with all browser whether on the web or not. The
web is just the place where it can expect to encounter all browsers (or
at least stand a chance of encountering them).
but most likely does work for the majority of
users. Also, it appears to degrade gracefully (not causing any
problems in browsers where it doesn't work) which is exactly what
we'd want.
Well, we have a thread about monitoring the mouseup event outside of the
window/document, and that definitely does not work on many browsers, and
then only under some circumstances (only when dragging in IE, for
example).

The code under discussion does make a reasonable attempt at clean
degradation, but it is a long way from being cross-browser, reliable or
good. And some of the implementation details make me think that it could
be extremely problematic on Safari or Konqueror (to name but two) with
the script partly running and then erroring mid process due to the use
of object-inference browser detection instead of the feature detection
that it almost achieves. That type of uncontrolled failure mid flow is
likely to undo the good work put into clean degradation by leaving the
page in an intermediate state that may not be nearly as viable as the
original HTML.
So, in summary, it appears to be a fantastic solution, IMO.


If you understood what the script was doing you would not be attaching
"fantastic" to it as a label. It is an above average script with some
serious design flaws and as a result should only be expected to exhibit
planned behaviour on the limited test-set of browsers stated in its
documentation.

It is actually a bit disappointing as a product of its author as his
vector graphics library is a really good implementation of efficient
line and arc drawing algorithms in javascript. Which contrasts horribly
with a script that even features an eval-ed dot notation property
accessor.

Richard.
Jul 23 '05 #18
"Randy Webb" <hi************@aol.com> wrote in message
news:7o********************@comcast.com...
Matt Kruse wrote:
Randy Webb wrote:
When I see code like this:
href="javascript:void(0)"
I tend to stop reading anymore, as the author code such as that isn't
very aware of reality on the web.

I don't think that's a fair statement.
Obviously, Mr. Zorn is not a newbie script kiddie, and to be so judgemental of his abilities based on a snippet of code is a bit unwarranted, IMO.


No, he is not a newbie script kiddie, but I still tend to discount code
written that has snippets of that in it. I also tend to discount code
that has attempted obfuscation in it, and thats based on his .js file.


I'm not sure if he has deliberately obfuscated it, but it isn't very clear,
that's for sure. His attitude seems to be "why do something in 10 lines when
you can do it all in one", and "why name something intuitively when you can
use two random letters". Maybe it's because he's German? :) However, it
seems to work well in IE anyway. As for Mandy's problem...

In IE you can capture the document.onmouseover event and return false from
it in order to cancel the default action (which is to stop updatng the mouse
coords beyond the window boundary). The mouse coords can then be read from
the event.clientX and event.clientY properties. Another side effect of doing
this is that the document.onmouseup event will now fire while the mouse is
outside the browser (while the browser is active). Note that setting the
event.cancelBubble property in the document.onmouseover event is independent
of cancelling the default action.

HTH
Jul 23 '05 #19
Matt Kruse wrote:
Andrew Thompson wrote:
Doesn't have the same ring to it as..
"50% failure rate in the 4 tests conducted."
..which is an accurate statement.
a) Flawed statistics are meaningless. "100% success rate in the browsers
used by 94% of site visitors" is another statistic which might be accurate.


His statistics aren't flawed. His choice of tests or his testing methodology
might be, causing him to get the failure rate he desires, but the statistics
themselves are (presumably) accurate. Of the four tests he chose to conduct, the
page failed half the time. The trick lies in finding the right four tests to
use.
b) Every single javascript every written will fail in at least one situation
This depends on how you define "failure". If the code never executes, then can
it be considered to have "failed".

I doubt <script type="text/javascript">var n = 0;</script> has ever failed in at
least one situation, unless you define failure to include not executing at all
(in the case of a user agent which does not support JavaScript, or JavaScript is
not enabled).
c) It doesn't really matter, since the solution does exist, works nicely in
a subset of browsers, and degrades gracefully - everything js code should
do. :)


I right-clicked the links in question and chose "Open Link in New Active Tab". I
got a blank document. Not too graceful a degradation.

I'm not particularly sure what would be so terribly wrong with:

<a href="noJS.html" onclick="...;return false;">...</a>

with noJS.html:

<html>
<head>
<title>JavaScript not enabled or link not single clicked</title>
</head>
<body>
<p>You need JavaScript enabled to enjoy what this link does. Be sure to single
click the link with your primary mouse button to activate it.</p>
</body>
</html>

Simple to implement, does not require much more work then <a
href="javascript:void(0);" ...> and would avoid silly arguments on usenet.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #20
Matt Kruse wrote:
Andrew Thompson wrote:
The natural assumption on this group is that you
are developing for the web unless otherwise stated.
On the web, it does not work. ( Note that you
have already had a 50% failure rate in the
4 tests conducted. )

It would be more correct to say that on the web, it does not work with all
browsers, but most likely does work for the majority of users. Also, it
appears to degrade gracefully (not causing any problems in browsers where it
doesn't work) which is exactly what we'd want.


When I tested it in Mozilla, it half worked. It let me drag it down, and
then when I released the mouse (expecting it to stop scrolling), it
continued to try to move the cat downwards. Even when I went to the top
of the document and clicked on it, it continued to try to scroll the cat
downwards. Not what I would consider "degrading gracefully".

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #21

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Frances Del Rio | last post: by
5 posts views Thread by Dag Sunde | last post: by
3 posts views Thread by mk | last post: by
1 post views Thread by Mango | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.