Applet and Javascript

F

Francois Lionet

Hello,

For my applet, I would like to know if it is possible to call Javascript
functions in the html page in which the applet is running. It is possible in
C++, it shoudl be in Java. Can someone direct me to the proper class and
methods?

Thanks, Francois
 
R

Richard Maher

Hi Francois,

Google for LiveConnect and/or JSObject, .call(func,args) is probably what
you're after.

Cheers Richard Maher
 
E

Evans

Hello,

For my applet, I would like to know if it is possible to call Javascript
functions in the html page in which the applet is running. It is possible in
C++, it shoudl be in Java. Can someone direct me to the proper class and
methods?

Thanks, Francois

It is important you understand that Java has nothing as such to do
with Javascript - they are two different languages.

Again, I do find it hard to grasp what you're looking for. Could you
give an example of what you're trying to achieve?
 
F

Francois Lionet

For my applet, I would like to know if it is possible to call Javascript
It is important you understand that Java has nothing as such to do
with Javascript - they are two different languages.

I know -of course- that Java has nothing to do with Javascript. I would just
like from my applet to execute some of the functions of the javascript code
present in the html code. Any idea on how to do this?
 
A

Andrew Thompson

...I would just
like from my applet to execute some of the functions of the javascript code
present in the html code. Any idea on how to do this?

It seems the JSObject mentioned by Richard might be
a better bet, than the ScriptEngine as alluded to by
Lew.

But, just curious.
Why did you reply to Evans but neither Richard nor Lew?
What did your searching (based upon the suggested
keywords) reveal?
 
A

Arne Vajhøj

Francois said:
I know -of course- that Java has nothing to do with Javascript. I would just
like from my applet to execute some of the functions of the javascript code
present in the html code. Any idea on how to do this?

It is very easy in Java:

JSObject window = JSObject.getWindow(this);
window.eval("myJSfunction()");

Arne
 
R

Richard Maher

Hi Arne,
window.eval("myJSfunction()");

Personally, I'd vote for call() over eval() any day.

There was also a detailed example posted here recently by Rolan de Ruiter: -
http://groups.google.com/group/comp.lang.java.programmer/msg/77df273bbc746620

(It looks really good, but on the 1.4 (dev) box I tried it on I got casting
errors so you'll probably need Java 6)

He manipulates the html/DOM directly from Java where some lazier people
(including moi) would have sent the width/height to a Javascript function
and seen if it couls be done from there.

Cheers Richard Maher

PS. I'm just working on a small Applet example that reads UDP messages in a
seperate thread with send some messages to a TextArea in a Frame and yet
others will cause the values of html <input > fields to change. From what
I've seen, multiple threads play happily with the browser event processing,
but I have to admit to being curious as to why it just works. Especially
with JSObject.call() being able to return a function result and the
potential for recursion with JS->Applet->JS->Applet->JS and so on. .
..(imagine a circle :)

PS. It looks like Java will be available on the iPhone after all? Does
anyone know more?
 
A

Andrew Thompson

It seems the JSObject ...might be a better bet,
than the ScriptEngine ...

For a live example of the ScriptEngine, try..
<http://pscode.org/jse.html>

It does not 'hook in' to the normal objects available
to JavaScript operating in browsers, such as the
window object, but does allow evaluation of expressions.
 
K

kz

Hi Arne,


Personally, I'd vote for call() over eval() any day.

There was also a detailed example posted here recently by Rolan de Ruiter: -http://groups.google.com/group/comp.lang.java.programmer/msg/77df273b...

(It looks really good, but on the 1.4 (dev) box I tried it on I got casting
errors so you'll probably need Java 6)

He manipulates the html/DOM directly from Java where some lazier people
(including moi) would have sent the width/height to a Javascript function
and seen if it couls be done from there.

Cheers Richard Maher

PS. I'm just working on a small Applet example that reads UDP messages in a
seperate thread with send some messages to a TextArea in a Frame and yet
others will cause the values of html <input > fields to change. From what
I've seen, multiple threads play happily with the browser event processing,
but I have to admit to being curious as to why it just works. Especially
with JSObject.call() being able to return a function result and the
potential for recursion with JS->Applet->JS->Applet->JS and so on. .
.(imagine a circle :)

PS. It looks like Java will be available on the iPhone after all? Does
anyone know more?









- Show quoted text -

Richard,

why would you prefer call over eval? what do u think are the major
problem in eval??
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top