在IE10中打破了getSelection()

Boh*_*kyi 6 javascript internet-explorer getselection internet-explorer-10

我在我的项目中使用window.getSelection()方法来生成可引用的文本

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

我使用的唯一代码:

text = window.getSelection().toString();
console.log(text);
Run Code Online (Sandbox Code Playgroud)

此代码调用mouseup事件.

有谁知道解决方案?

K3r*_*l31 2

试试这个应该适用于 ie < 9.0

var texttest = document.selection.createRange();
alert (texttest.text);
Run Code Online (Sandbox Code Playgroud)

这适用于除 ie < 9.0 之外的所有浏览器

var texttest = document.getSelection();
alert(texttest);
Run Code Online (Sandbox Code Playgroud)