【发布时间】:2013-01-28 22:20:46
【问题描述】:
我正在使用以下函数来获取选定的文本,它在所有主流浏览器中运行良好,但在 IE 9 之前的版本中无法正常运行!
function getSelected() {
var t = '';
if (window.getSelection) {
t = window.getSelection();
} else if (document.getSelection) {
t = document.getSelection();
t = t.toString();
} else if (document.selection) {
t = document.selection.createRange();
t = t.text;
}
return t;
}
var txt = getSelected();
这里的问题是 IE 在版本 9 之前它不会在变量“txt”中存储任何文本
【问题讨论】:
-
stackoverflow.com/questions/5643635/… 的可能重复项,看看是否对您有帮助。
-
我的 IE 问题 这段代码适用于所有浏览器,但不适用于 IE
标签: javascript internet-explorer getselection