I needed to write a quick bit of code today to track when a user selects any text on a page. The key was to bind a method to the "mouseup" event which would grab the selected text and do something with it. This was plain 'ole JS and thankfully <a href="http://dean.edwards.name">Dean Edwards</a> and <a href="http://crisp.tweakblogs.net/">Tino Zijdel</a> had created a nice <a href="http://therealcrisp.xs4all.nl/upload/addEvent_dean.html">cross-browser event handler routine</a> which worked great. And <a href="http://davidwalsh.name/">David Walsh</a> has a <a href="http://davidwalsh.name/text-selection-ajax">nice post on similar functionality</a> using MooTools & jQuery so I was able to leverage some of that code that deals with grabbing the selected text:

[code lang="js"]
function findSelected() {
	if(window.getSelection) { 
		return window.getSelection(); 
	}
	else if(document.getSelection) { 
		return document.getSelection(); }
	else {
		var selection = document.selection &amp;&amp; document.selection.createRange();
		if(selection.text) { 
			return selection.text; }
		return false;
	}
	return false;
}

function getSelectedText() {
	var selected = findSelected();
	if(selected &amp;&amp; (selected = new String(selected).replace(/^\s+|\s+$/g,''))) {
		alert( selected );
	}
}
[/code]

From there it was just a matter of actually binding the method to "mouseup":

[code lang="js"]
addEvent(document,&quot;mouseup&quot;,getSelectedText);
[/code]

All this seemed great and it worked perfectly in Internet Explorer and Firefox but when I tried it on Chrome, I found an issue.
