您好,我有问题,我的第一个插件.. 我尝试使用此功能为什么选定的文本不显示?
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);
}
在我的XUL
我用这种方式执行上述功能选择的网站页面上的字:
<menuitem id="inlinetransContextMenuPage"
label="Terjemahkan dengan inlinetrans"
onclick="overlay.getText()" />
</popup>
但为什么我当我选择页面上的字的字无法显示(弹出的是空白)..
@ Tim Down:当我使用window.getSelection()。toString()时,它仍然不起作用。但是当我尝试使用document.commandDispatcher.focusedWindow.getSelection()。toString();它的工作。为什么选择的单词不能以第一种方式出现,并且可能以第二种方式出现.. ?? – user495688 2010-12-20 01:17:13
@ user495688你真的在使用单个窗口吗?代码'window == document.commandDispatcher.focusedWindow'输出true或false? – 2010-12-20 15:24:16
@ Tom Barito:它的工作原理..:D – user495688 2010-12-20 15:46:04