How to make sure each onmousedown has an onmouseup?

my script looks something like this:

<body onmouseup=“b.innerHTML=‘2’;”>
<button id=“b” onmousedown=“this.innerHTML=‘1’;”/>

now the problem is that if the user presses the button, and while he have not released the button, he Alt-Tab to another window and release the mouseclick at the other window. And when he returned to my webpage, the mouseup event never occured and is “lost”!

how do we stop this from happening?

There is no way of capturing a mouseup event after they have moved the mouse off of the tag. The best you can do is to set a timeout that will trigger the same code as the mouseup if it doesn’t happen within a certain time period.

The situation being discussed is that when the mouse button is released it isn’t the browser that gets the mouseup to process. A browser can only process events that occur within the browser. If Microsoft Word gets the mouseup event then it doesn’t matter what browser you are running that doesn’t get it. There is nothing whatever you can place in a web page to capture mouseup events when they happen outside of the browser.

Some browsers do allow you to capture a blur event when the window loses the focus but it is non-standard and so most browsers don’t even know that the person left the browser.

Microsoft Word and any other application don’t need to matter what application captures mouse events, the operating system resolves it.
In that case, the operating system notifies the application that it loses the mouse capture so the onlosecapture event is fired on the button in IE.

I know, event capturing does not work perfectly in all browsers, but the example code works in all browser, in most of the cases and I think, it will be useful to Pacerier.