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

javascript - jquery in rhino - Stack Overflow

programmeradmin3浏览0评论

I'm trying to load jquery into Rhino as demonstrated by this link here. But I keep getting the following error:

line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null

I think it's that jQuery is failing to load altogether - but I have no idea why. I'm using the same index.html file that the author posted in source control.

Here is the trace from my Rhino console:

js> load( "/temp/env.js" );
js> window.location = '/temp/index.html';
/temp/index.html
js> load( "/temp/jquery.js" );
js: "/temp/jquery.js", line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null
    at /temp/jquery.js:1086
    at /temp/jquery.js:1079
    at /temp/jquery.js:16
    at <stdin>:41

Any ideas?

I'm trying to load jquery into Rhino as demonstrated by this link here. But I keep getting the following error:

line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null

I think it's that jQuery is failing to load altogether - but I have no idea why. I'm using the same index.html file that the author posted in source control.

Here is the trace from my Rhino console:

js> load( "/temp/env.js" );
js> window.location = '/temp/index.html';
/temp/index.html
js> load( "/temp/jquery.js" );
js: "/temp/jquery.js", line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null
    at /temp/jquery.js:1086
    at /temp/jquery.js:1079
    at /temp/jquery.js:16
    at <stdin>:41

Any ideas?

Share Improve this question edited Nov 4, 2012 at 23:13 isomorphismes 8,40311 gold badges61 silver badges72 bronze badges asked Feb 23, 2011 at 9:27 javamonkey79javamonkey79 17.8k38 gold badges116 silver badges177 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 5

I was using an OLD version of the env.js file. It turns out the author's really ran with it and moved it over to it's own sites, etc, etc.

The new stuff is here.

As soon as I started using it it was golden with jQuery 1.5.

I don't think jQuery (and many other web JS libraries) will work in Rhino because that JavaScript runtime doesn't provide the expected "browser globals" like "document", "navigator", etc. The error message you list indicates that the library is trying to read an attribute (or call a method) of some (presumably browser) object that doesn't exist in the Rhino environment.

The "env.js" project should do exactly this sort of browser environment mockup but it appears to be experimental and might not be patible with the version of jQuery you're trying to use.

I succeeded in running jquery in Rhinojs using instructions from here:

http://geek.michaelgrace/2011/09/rhino-and-envjs/

My steps:

wget ftp://ftp.mozilla/pub/mozilla/js/rhino1_7R2.zip
wget http://www.envjs./dist/env.rhino.1.2.js
wget http://code.jquery./jquery-1.8.2.js
unzip rhino1_7R2.zip
java -jar rhino1_7R2/js.jar
load("env.rhino.1.2.js");
load("jquery-1.8.2.js");

I believe jQuery is useless in Rhino - you have neither DOM nor Ajax. JavaScript 5 (supported in Rhino 1.7R3) has many required fearures, like JSON global object or array methods like forEach() or map().

发布评论

评论列表(0)

  1. 暂无评论