How to access the user's selection in the browser?
I'm trying to write an extension for chrome that operates 开发者_如何学编程on a user's selection on a webpage. How can I get access to the selected text from a chrome plugin?
Thanks, Joshua
I don't know anything about Chrome plug-ins, but I imagine they have access to the regular window
object. This is how you do it in a web page:
var sel = window.getSelection();
var selectedText = sel.toString();
Check this (experimental) copy stuff. I think it's just what you need.
Also, the context menu api (not experimental) gives you a onClickData which contains the selection text.
精彩评论