最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

DOM implementation in pure javascript? - Stack Overflow

programmeradmin3浏览0评论

Is there an implementation or emulation of the DOM which is purely javascript?

  • There is env.js, but that requires Rhino.
  • There's jsdom, but that requires Node.

Is there a solution that works in most any javascript interpreter, such as v8, without being tied to any particular interpreter or engine? That is, is there any DOM implementation in JS that without any set up or shims can be dropped into a javascript interpreter and just run?

Is there an implementation or emulation of the DOM which is purely javascript?

  • There is env.js, but that requires Rhino.
  • There's jsdom, but that requires Node.

Is there a solution that works in most any javascript interpreter, such as v8, without being tied to any particular interpreter or engine? That is, is there any DOM implementation in JS that without any set up or shims can be dropped into a javascript interpreter and just run?

Share Improve this question edited Mar 14, 2012 at 22:06 Mario asked Mar 14, 2012 at 21:47 MarioMario 2,9421 gold badge27 silver badges38 bronze badges 4
  • Could you explain why you need this? – JPuge Commented Mar 15, 2012 at 18:38
  • It's to test javascript code. – Mario Commented Mar 17, 2012 at 2:30
  • 1 I am looking for something similar, here is the reason for me: I want to run it in v8 js engine (controlled by golang bindings to v8), but not necessarily in node. – Helin Wang Commented Jun 2, 2015 at 21:54
  • @JPuge Questions like this always turn out to be retarded as the time goes on. The reasons may include: Using DOM in web workers, using DOM in custom native application that runs HTML and Javascript, using javascript to validate some HTML files... – Tomáš Zato Commented Nov 11, 2015 at 13:07
Add a ment  | 

2 Answers 2

Reset to default 5

In addition to the ones you have listed, I have heard good things about dom.js. It requires limited ES6 features such as const, WeakMap, and Proxy, so it will work in V8 and SpiderMonkey (Rhino) but not JavaScriptCore, Chakra, or others.

It's hard to guess at exactly what you're trying to do, here, but I'll take a stab at it, just to keep the conversation going:

  • If you're trying to manipulate a DOM from within a browser, can't you just use Jquery?
  • If you're trying to get a "headless browser", I'd check out PhantomJS.

I guess it's hard to imagine how you'd even run Javascript code without a browser, or Rhino, or Node, or PhantomJS, or some other JS interpreter environment...

发布评论

评论列表(0)

  1. 暂无评论