无法获取未定义或空引用的属性“createRange” [英] Unable to get property 'createRange' of undefined or null reference
问题描述
以下代码在我升级到Windows 8.1 / Internet Explorer 11之前运行良好,现在抛出一个错误:无法获取未定义或空引用的属性'createRange'
The following code, which worked well right up until I upgraded to windows 8.1 / Internet Explorer 11, is now throwing an error: "Unable to get property 'createRange' of undefined or null reference"
var SelectedData = window.external.menuArguments.document.selection.createRange().text;
是否有修复/解决方法?
Is there a fix / work around for this?
* 问题更新如下,新代码仍然无法使用....
* Question updated below with newer code that is still not working ....
<html><head><title>-</title><script type="text/JScript">
function Launch()
{
var TheSelection = document.getSelection();
if(TheSelection != null)
{
.... do a bunch of stuff
}
window.close();
}
</script></head><body onload="Launch();" </body></html>
我也试过
window.getselection;
window.getselection();
window.getselection()。tostring();
I have also tried window.getselection; window.getselection(); window.getselection().tostring();
这些似乎都不起作用...... ???
none of these seem to work ...???
推荐答案
document.selection
的文档在右上角说:
The documentation for document.selection
says right at the top:
不再支持
选择。从Internet Explorer 11开始,使用getSelection。有关信息,请参阅兼容性更改。
selection is no longer supported. Starting with Internet Explorer 11, use getSelection. For info, see Compatibility changes.
更改 document.selection.createRange()。text
到 document.getSelection()
。
这个问题正是我预测的。您在null或undefined引用上调用 createRange()
。具体来说, document.selection
未定义。错误消息确切地说错了。
The problem was exactly what I predicted. You are calling createRange()
on a null or undefined reference. Specifically, document.selection
is undefined. The error message said exactly what was wrong.
这篇关于无法获取未定义或空引用的属性“createRange”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!