开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜