Javascript 使用mozrepl时,document.getElementById()返回null(但在firebug中不返回)
我正在尝试使用Firefox扩展从emacs中为我提供一个Javascript REPL 我想我已经把它安装好了。我可以与emacs中的REPL交互,并且可以像教程页面中描述的那样浏览文档。当我尝试做一些非常简单的事情时,问题就出现了,比如获取画布元素的上下文:Javascript 使用mozrepl时,document.getElementById()返回null(但在firebug中不返回),javascript,firefox-addon,firefox3.6,Javascript,Firefox Addon,Firefox3.6,我正在尝试使用Firefox扩展从emacs中为我提供一个Javascript REPL 我想我已经把它安装好了。我可以与emacs中的REPL交互,并且可以像教程页面中描述的那样浏览文档。当我尝试做一些非常简单的事情时,问题就出现了,比如获取画布元素的上下文: repl> document.getElementById("mycanvas").getContext("2d") !!! TypeError: document.getElementById("mycanvas") is nu
repl> document.getElementById("mycanvas").getContext("2d")
!!! TypeError: document.getElementById("mycanvas") is null
Details:
message: document.getElementById("mycanvas") is null
fileName: chrome://mozrepl/content/repl.js -> file:///C:/Users/teamonkey/AppData/Roaming/Mozilla/Firefox/Profiles/chfdenuz.default/mozrepl.tmp.js
lineNumber: 1
stack:
@chrome://mozrepl/content/repl.js -> file:///C:/Users/teamonkey/AppData/Roaming/Mozilla/Firefox/Profiles/chfdenuz.default/mozrepl.tmp.js:1
name: TypeError
不仅仅是那个实例:对getElementById的任何调用都将返回null
如果我启动firebug,我可以输入相同的内容,它将返回一个有效的上下文,但我真的希望REPL在emacs中工作。我不认为这是一个bug,但我可能没有正确配置mozrepl。有人能帮忙吗
Mozrepl 1.0、Firefox 3.6启动时,您处于浏览器窗口本身的上下文中,而不是任何特定文档。您可以访问chrome元素(菜单、工具栏、选项卡等)。
文档
对象当前指向浏览器窗口
要将上下文切换到活动选项卡中的文档,请使用:
repl.enter(content)
现在,document
对象是在活动选项卡中加载的文档,因此您可以访问它的DOM树并可以对其进行操作