在IE10中打破了getSelection()

时间:2013-04-27 21:27:30

标签: javascript internet-explorer internet-explorer-10 getselection

我在项目中使用 window.getSelection()方法制作可引用文本

它在所有现代浏览器中运行得很好,不管IE10如何。在IE10控制台中返回正确的文本,但选择中断。

我使用的唯一代码:

text = window.getSelection().toString();
console.log(text);

此代码调用 mouseup 事件。

有谁知道解决方案?

1 个答案:

答案 0 :(得分:2)

尝试这应该适用于ie< 9.0

var texttest = document.selection.createRange();
alert (texttest.text);

这适用于所有浏览器,除了< 9.0

var texttest = document.getSelection();
alert(texttest);