Firefox addon, accessing selection object via javascript
the javascript file contains this code:
function getSelected(win) {
sel = win.getSelection();
alert(sel);
}
开发者_开发问答
The browser.xul file contains this:
<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. You probably need to use content
instead:
function getSelected() {
var sel = content.getSelection();
alert(sel);
}
Check this resources for more info:
- Firefox Extension: Get selected text
- http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/2d106d26d8592bff?pli=1 (The Mozilla page that he points to is really useful)
精彩评论