使用 mozrepl 时 document.getElementById() 返回 null (但在 firebug 中则不然)
我正在尝试使用 mozrepl Firefox 扩展从 emacs 中为我提供 Javascript REPL 。
我想我已经正确设置了。我可以从 emacs 与 REPL 进行交互,并且可以像教程页面中描述的那样浏览该文档。当我尝试做一些非常简单的事情时,比如获取画布元素的上下文,问题就出现了:
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 中工作。我不认为这是一个错误,但我可能没有正确配置 mozrepl。有人可以帮忙吗?
莫兹雷普 1.0、火狐 3.6
I'm trying to use the mozrepl Firefox extension to give me a Javascript REPL from within emacs.
I think I've got it set up correctly. I can interact with the REPL from emacs and can explore the document pretty much as described in the tutorial pages. The problem comes when I try to do something really simple, like get a context to a canvas element:
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
It's not just that particular instance: any call to getElementById will just return null.
If I start up firebug I can enter the same thing and it will return a valid context, but I'd really like to get the REPL working in emacs. I don't think this is a bug but I've probably not configured mozrepl correctly. Can anyone help?
Mozrepl 1.0, Firefox 3.6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您开始时,您处于浏览器窗口本身的上下文中,而不是任何特定的文档。您可以访问镶边元素(菜单、工具栏、选项卡等)。
document
对象当前指的是浏览器窗口。要将上下文切换到活动选项卡中的文档,请使用:
现在
document
对象是活动选项卡中加载的文档,因此您可以访问其 DOM 树并可以操作它。When you start, you are in the context of browser window itself, not any particular document. You have access to chrome elements (menus, toolbars, tabs, etc). The
document
object currently refers to browser window.To switch context to the document in active tab use:
Now
document
object is the document loaded in active tab, so you have access to its DOM tree nad can manipulate it.