hi i have problem with my first addons..
i try to select the word on the website page with this function
function getSelected() {
var userSelection;
if (window.getSelection) {
userSelection = window.getSelection();
} else if (document.selection) {
userSelection = document.selection.createRange();
}
return userSelection;
}
function getText() {
var select = getSelected()+ "";
alert(select);
}
in my xul i execute the function above with this way :
<menuitem id="inlinetransContextMenuPage"
label="Terjemahkan dengan inlinetrans"
onclick="overlay.getText()" />
</popup>
but why i the word cannot appear when i select word on page (the pop up is blank)..
window.getSelection()returns the selection from the chrome window, which is nearly always empty. As you discovered, you need to usedocument.commandDispatcher.focusedWindowto find out which window has the active selection. (If you’re lazy you might have triedcontent.getSelection()but that only works if the page has no frames.)