我们知道,从选定文本的HTML页面是一个基本的东西。但我认为代码是没有广泛使用。下面的JavaScript代码获取textarea的页面,输入文本字段的形式,包括在任何地方的价值。function GetSelectedText()
{
var selectedText=(
window.getSelection
?
window.getSelection()
:
document.getSelection
?
document.getSelection()
:
document.selection.createRange().text
);
if(!selectedText || selectedText=="")
{
if(document.activeElement.selectionStart)
{
selectedText = document.activeElement.value.substring(
document.activeElement.selectionStart
. document.activeElement.selectionEnd);
}
}
return selectedText;
}
这里是英语和泰米尔语词典奖金bookmarklets的。{C}
{体C3}
//English to Tamil
javascript:var%20newfunc=function%20a(){q=window.getSelection?window.
getSelection():document.getSelection?document.getSelection():
document.selection.createRange().text;if(!q||q=="")
{if(document.activeElement.selectionStart)
{q= document.activeElement.value.substring
(document.activeElement.selectionStart,document.activeElement.selectionEnd)}}
if(!q||q=="")q=prompt("Enter%20word:");if(q!=null)window.open
('http://www.eudict.com/index.php?lang=engtam&word='+q)}()