博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Rhino and Envjs
阅读量:6233 次
发布时间:2019-06-22

本文共 2349 字,大约阅读时间需要 7 分钟。

Rhino and Envjs

 is an open source implementation of JavaScript in Java and is a simulated browser environment written in javascript. So what does all this mean? It means that you can load up a web page and execute the loaded page’s JavaScript in a browser simulated environment all without a browser! Let me demonstrate.

From the  I downloaded  since R3 doesn’t work with Envjs at the time of this post.

I also downloaded the latest  and placed it in the same location as the unzipped rhino folder.

Navigate in a terminal to the location of the unziped rhino folder and start up rhino.

java -jar js.jar

Then you will want to load the Envjs JavaScript that will emulate the browser environment. (location is relative to where the jar file is running from)

load("../env.rhino.js")

Then I tell Envjs to load external scripts found in the page. This is required because scripts running in Rhino with Envjs will have file system access.

Envjs.scriptTypes['text/javascript'] = true;

Then we navigate our emulated browser to the test page that I built.

window.location = "http://mikegrace.s3.amazonaws.com/geek-blog/rhino-envjs.html"

The test page that I built looks like this when you load it in a browser with JavaScript disabled

This is because the page content is built using jQuery

Rhino and Envjs Test

Because Envjs will emulate a browser, we will be able to work with the page in Rhino like we would in a browser.

Getting the paragraph text is as easy as running some jQuery in the Rhino console

jQuery("p").text();

Awesome!

rhino1_7R2 mgrace$ java -jar js.jarRhino 1.7 release 2 2009 03 22js> load("../env.rhino.js")[  Envjs/1.6 (Rhino; U; Mac OS X x86_64 10.6.8; en-US; rv:1.7.0.rc2) Resig/20070309 PilotFish/1.2.13  ]js> Envjs.scriptTypes['text/javascript'] = true;truejs> window.location = "http://mikegrace.s3.amazonaws.com/geek-blog/rhino-envjs.html"http://mikegrace.s3.amazonaws.com/geek-blog/rhino-envjs.htmljs> jQuery("p").text();Question: What is the answer?js> jQuery("code").text();42

If you are looking to debug your scripts in Rhino a bit better, you can launch the rhino console in the Rhino JavaScript Debugger using a command similar to this

java -cp js.jar org.mozilla.javascript.tools.debugger.Main

rhino javascript debugger

: A 25 year old Geek that loves his wife and enjoys tech, photography, outdoors, and his motorcycle.

转载地址:http://qoqna.baihongyu.com/

你可能感兴趣的文章
JavaScript变量和作用域
查看>>
开源SIP服务器加密软件NethidPro升级
查看>>
作业:实现简单的shell sed替换功能和修改haproxy配置文件
查看>>
Altium 拼板方法以及 注意的 地方
查看>>
Apache Pulsar中的地域复制,第1篇:概念和功能
查看>>
python pip install 出现 OSError: [Errno 1] Operation not permitted
查看>>
从源码分析scrollTo、scrollBy、Scroller方法的区别和作用
查看>>
ObjectOutputStream和ObjectInputStream
查看>>
nagios客户端未启动报错
查看>>
南京大学周志华教授当选欧洲科学院外籍院士
查看>>
马士兵教学语录
查看>>
计算机网络与Internet应用
查看>>
MongodDB学习笔记(二)(复制)
查看>>
oracle在线迁移同步数据,数据库报错
查看>>
linux性能剖析工具
查看>>
PHP模拟发送POST请求之四、加强file_get_contents()发送POST请求
查看>>
搞懂“分布式锁”,看这篇文章就对了
查看>>
给自己出的iOS面试题
查看>>
React as a UI Runtime(四、条件)
查看>>
flutter中的异步
查看>>