我正在尝试自己写一个简单的兼容firefox和ie的在线编辑器,但是遇到点麻烦。
下面这个函数可以取得页面中文本框被高亮选择的文字,但为什么无法取得iframe里选中的文字?得到的总是空值,请问是怎么回事?。
alert(getFieldSelection(iframe_div.document.body));">function getFieldSelection(select_field)
{
word='';
if (document.selection) {
var sel = document.selection.createRange();
if (sel.text.length > 0) {
word = sel.text;
}
}
else if (select_field.selectionStart || select_field.selectionStart == '0') {
var startP = select_field.selectionStart;
var endP = select_field.selectionEnd;
if (startP != endP) {
word = select_field.innerHTML.substring(startP, endP);
}
}
return word;
}