Calling Javascript from Java

?

.

Greetings,

Here is my problem, hopefully you can help me. I have a javascript
function on a web site that I need to call from Java. The script is
located in http://www.some.bogus.site.com/product/script.js and the
function is called encrypt(). It takes as an input a string and returns a
different string. I have a Java application with the input string and need
to get the output script. I've been told I can use javascript: protocol to
access it via java.net.URL.

Does anyone have a code snippet that would call the function
encrypt("password") from a given javascript file and return the results as
a string in Java?
 
?

.

..I have a javascript
function on a web site that I need to call from Java. ..
Does anyone have a code snippet that would call the function
encrypt("password") from a given javascript file and return the results as
a string in Java?

For info. about Java/JS[1] interaction - I generally check
Real's How-To[2] for tips..

[1] <http://www.rgagnon.com/framesets/java-js.html>
[2] <http://www.rgagnon.com/howto.html>

Thank you for the response. Unfortunately, the above solution is Netscape
and Windows specific. I'm trying to automate unit tests for a variety of
different browsers on a variety of different platforms
 
A

Andrew Thompson

Unfortunately, the above solution is Netscape
and Windows specific.

What do you mean? That stuff works just fine in IE,
I am sure I have seen it work on Opera as well.
Give us some test URL's.

What specific information suggests to you that it only works in NN?
[ Don't be fooled by the LiveScript package names! ]
 
?

.

Unfortunately, the above solution is Netscape
and Windows specific.

What do you mean? That stuff works just fine in IE,
I am sure I have seen it work on Opera as well.
Give us some test URL's.

What specific information suggests to you that it only works in NN?
[ Don't be fooled by the LiveScript package names! ]

I just re-read the web site and notice that it is on more than just
Netscape/Windows.

I had been searching around before I posted the message and read somewhere
that the JSObject solution only worked on Netscape/Windows. Other web
sites were suggesting using java.net.URL and open a "javascript:" URL.
I've since read that this only works if the script does not return
anything and just displays something, e.g. "javascript:var now = new
Date(); now".

I'll have another look at the JSObject and see if that solves things for
me.

Thanks,
Darrell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top