In the Chrome extension I'm working on right now, there's a situation where if the user right-clicked on this link:
<a href="http://www.google.com">Hello</a>
and selected a certain option from my extension's context menu, I need the string "Hello" to be captured in some form. As the Context Menus API shows, it's easy to capture text from a right-clicked selection or the actual URL of the hyperlink (in this case, Google.com) , since these appear in OnClickData, but I'm not sure how I would capture the text from a link.
As a side note, if a user highlights a hyperlink and tries to use my context menu, it doesn't work. However, it works properly if the user highlights normal text. I do have "link" and "selection" enabled under "contexts" when I create the context menu option.
It seems, that there's no straightforward way to do it. But there are some workarounds until this kind of feature is implemented. From http://code.google.com/p/chromium/issues/detail?id=39507
"I figured out a hack that you can use to get around it for now. I used it in Cloudboard: You can executeScript on the page and use: document.activeElement to get the currently selected element. You can use: document.activeElement.selectionStart, document.activeElement.selectionEnd to get the selected text and document.activeElement.value.substr()"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With