简体   繁体   English

Firefox插件,通过javascript访问选择对象

[英]Firefox addon, accessing selection object via javascript

the javascript file contains this code: javascript文件包含以下代码:

function getSelected(win) {
    sel = win.getSelection();
    alert(sel);
}

The browser.xul file contains this: browser.xul文件包含以下内容:

<popup id="contentAreaContextMenu">
  <menuitem id="selection" label="Select text" accesskey="S" 
   oncommand="getSelected(window);"/>
</popup> 

The alert is blank, why? 警报为空白,为什么?

The window object you are using in the getSelection function is the browser's window, not the document's window. 在getSelection函数中使用的窗口对象是浏览器的窗口,而不是文档的窗口。 You probably need to use content instead: 您可能需要改用content

function getSelected() {
    var sel = content.getSelection();
    alert(sel);
}

Check this resources for more info: 检查此资源以获取更多信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM