开发者

How to access the user's selection in the browser?

开发者 https://www.devze.com 2023-01-27 18:28 出处:网络
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?

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

精彩评论

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