开发者

document.getElementById() returns null when using mozrepl (but not in firebug)

I'm trying to use the mozrepl Firefox extension to give me a Javasc开发者_JAVA百科ript 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


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:

repl.enter(content)

Now document object is the document loaded in active tab, so you have access to its DOM tree nad can manipulate it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜