开发者

Event on HTML selection

Is there an event for situations where something is selected on an HTML page like arbitrary text within a span element? Does such a thing exist or d开发者_如何学编程oes one need to poll at regular interval & analyze the window.getSelection() ?

I would like to trap this event type from within a browser extension (Chrome).


New York Times implements some "on selection" type of functionality on all their articles without monitoring for a specific "onselection" event. Example here, highlight some text and you'll see a "?" pop up that you can use for search.

Here's the relevant code. Basically looks like onmouseup of any body text, they get the document (or window) selection and use that.

The existing "onselect" event is spec'd to only apply to input and textarea elements.


In jQuery you can use the select() function to bind an event handler to the select event. For more info, see http://api.jquery.com/select/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜