从internet explorer上下文菜单通过JS访问DOM



我想从Internet Explorer的上下文菜单中通过javascript操作DOM。为此,我在注册表中创建了一个密钥:

[HKEY_CURRENT_USERSOFTWAREMicrosoftInternet ExplorerMenuExtRemove Node]
@="javascript:var d=document,h=d.head,b=d.body,css='<style>tr{border:solid 1px red;}</style>';h.innerHTML.indexOf(css)==-1?h.innerHTML+=css:h.innerHTML=h.innerHTML.replace(css,'');b.addEventListener('mousedown',function(c){var t=c.target;if(c.ctrlKey){c.preventDefault();t.style.display='none';}});void(0);"
"Contexts"=dword:00000001

但它并没有处理这样的错误:">文档引用未定义或为空";。然后我尝试了更简单的方法,比如alert("something"(,它正确地显示为">某事";。我还尝试了更简单的DOM引用,例如alert(document.title(返回空。

如何从Internet Explorer的上下文菜单访问DOM元素?

提前谢谢。

好吧,我自己用外部html文件解决了这个问题javascript URI。如果有人需要,他们应该这样做:

[HKEY_CURRENT_USERSOFTWAREMicrosoftInternet ExplorerMenuExtRemove Node]
@="c:pathtothe_html_file.html"
"Contexts"=dword:00000001

和_html_file.html文件:

<html>
<script language="javascript" defer>
var docment=window.external.menuArguments.document;
// now it works!
alert(docment.title);
</script>
</html>

有关更多信息:将条目添加到标准上下文菜单

最新更新