Yesterday, I wrote about an issue I was having with Google & Safari's way of handling text selection & the "mouseup" event versus Firefox & IE. It was an odd scenario but using a closure I found a workaround. This morning I was happy to see a comment from my friend Diego Perini with an explanation of what he feels is the cause and also an alternative fix. 



<blockquote>you have setup an on “mouseupâ€ event so it is normal it fires each time you release the mouse button. You are filtering “mouseupâ€ to act only if a selection exists, that’s ok. Unfortunately the difference between the browsers you mention is that in Firefox the selection is cleared as soon as the next “mousedownâ€ while in Safari/Chrome it is cleared on “mouseupâ€ so when fired your filtering will still find a selection active on Safari/Chrome, thus the second alert you see.

This is how you can alternatively fix that problem, just add these lines:

[code lang="js"]
function clearSelectedText() {
if (window.getSelection) {
window.getSelection().removeAllRanges();
} else if (document.getSelection) {
document.getSelection().empty();
} else {
var selection = document.selection &amp;&amp; document.selection.createRange();
if (selection.text) {
selection.collapse(true);
selection.select();
}
}
}

addEvent(document, “mousedownâ€, clearSelectedText);
[/code]
Hope this help fix it and explain what happens in Safari/Chrome, I wouldn’t mark this as a bug. Have fun.</blockquote>

