IE其他版本的获取方式如下:
var isIE=!!document.all;
if(isIE){
var rng=window.getSelection.createRange();
str = rng.text;
} else {
var s = window.getSelection();
str = s.toString();
}
请问IE11下如何获取?
I think, I found a solution. Not the best and nicest but it is working for me: I can create the exact same TextRange from Selection.
这涉及到权限,不通用,只能抛弃该属性
document.selection改成window.getSelection
https://msdn.microsoft.com/zh-cn/library/ie/bg182625(v=vs.85).aspx
IE11你已经判断错了。。IE11不再支持document.all,要下面的方式判断
function isIE() { //ie?
if (!!window.ActiveXObject || "ActiveXObject" in window)
return true;
else
return false;
}
IE11支持var s = window.getSelection();,你判断IE正确就可以获取到选中的内容了,不过注意由于安全问题file对象无法通过这个获取到选中的路径。。
应该用selection的API来判断
if (window.getSelection) {//IE11+ 或者标准浏览器
str = window.getSelection().toString();
}
else if (document.selection) {//IE10-
str = document.selection.createRange().text;
}
charuuou uojoj
> jkk[[[;
楼上说的方法已经亲测 w7专业版 +ie11 得到是空的没值~~
var isIE=!!document.all;
if(isIE){
var rng=document.activeElement.value;
str = rng;
}
测试以上均无解,在IE11下,为什么无法获取选取 的文本?
IE11支持var s = window.getSelection(); 这个不支持呀?????