简体   繁体   English

来自Java的Javascript - 文档对象

[英]Javascript from Java - document object

I am trying to invoke a java script function that creates a html div structure by using eg 我试图通过使用eg来调用创建html div结构的java脚本函数

/* ... */
document.createElement("div");
/* ... */

Unfortunately I have no window and/or document object if I'm running this script directly from Java in contrast of running it in the browser. 不幸的是,如果我直接从Java运行这个脚本,而不是在浏览器中运行它,那么我没有窗口和/或文档对象。 May somebody give me a piece of advise how to use or modify the javascript code? 可能有人给我一些建议如何使用或修改javascript代码? Is there a way to create a document object by myself? 有没有办法自己创建文档对象? Thanks a lot. 非常感谢。

Best regards 最好的祝福

Sascha 萨沙

Rhino and Nashorn do not supply browser objects like window and document . Rhino和Nashorn不提供windowdocument等浏览器对象。 If you want those objects, you'll have to supply them yourself. 如果你想要那些物品,你必须自己提供。 Try HTMLUnit , which provides implementations of those objects for the purposes of writing unit tests. 尝试HTMLUnit ,它提供这些对象的实现,以便编写单元测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM