在我现在正在处理的Chrome扩展中,如果用户在此链接上单击右键,则会出现这种情况:
<a href="http://www.google.com">Hello</a>并从我的扩展的上下文菜单中选择了某个选项,我需要字符串“Hello”以某种形式捕获。 正如上下文菜单API所显示的那样,从右键单击的选择或超链接的实际URL(在本例中为Google.com)捕获文本很容易,因为它们出现在OnClickData中,但我不知道该怎么做从链接中捕获文本。
请注意,如果用户突出显示超链接并尝试使用我的上下文菜单,则不起作用。 但是,如果用户突出显示普通文本,则它可以正常工作 当我创建上下文菜单选项时,我确实在“上下文”下启用了“链接”和“选择”。
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.
最满意答案
看来,没有直接的方法来做到这一点。 但是在实现这种功能之前还有一些解决方法。 从http://code.google.com/p/chromium/issues/detail?id=39507
“我发现现在可以用它来解决这个问题,我在Cloudboard中使用它:你可以在页面上执行Script并使用:document.activeElement来获取当前选定的元素,你可以使用:document.activeElement。 selectionStart,document.activeElement.selectionEnd获取选定的文本和document.activeElement.value.substr()“
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()"
更多推荐
发布评论