sumitkjm 0 Newbie Poster

Hi,

I am working to call java script function from java program. I am able to do with simple javascript functions like below:

    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("JavaScript");
    engine.eval("function printHello(Str) { print('Hello World') } printHello('Hello World')");

But not able to do the javascript function which includes any in built browser reference objects like, document.write('Hello') etc..

How can I invoke these java scripts functions from a stand alone java program.

Some times it seems to me like these kind of functions where any browser based object is referenced can be executed only via browser. Is there any way by ignoring or replacing these reference get the actual java script code run.

In other words is it possible to run any browser in back end, which can be triggered by a java program and read the content via InputStream.

Thanks for help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.