For Programmers: Free Programming Magazines  


Home > Archive > Java Help > January 2008 > Applet and the JavaScript









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Applet and the JavaScript
bH

2008-01-17, 7:20 pm

Hi All,

I am . Given the two codings below:
the Applet and the JavaScript, is it correct to say that
the Applet is calling the Javascript or the Javascript is
calling the Applet?

Your help is appreciated.

bH

import java.applet.*;
import java.net.*;

public class inJava extends Applet{
public void init(){
String msg1 = "We will jump to an HTML tag";
String msg2 =
"http://www.extension.iastate.edu/gif/Balls/l_green.gif";
try {
getAppletContext().showDocument
(new URL("javascript:doAlert(\"" + msg1 +"\")"));
getAppletContext().showDocument
(new URL("javascript:jumpTo(\"" + msg2 +"\")"));
}
catch (MalformedURLException me) { }
}
}


<HTML><HEAD></HEAD><BODY>
<SCRIPT>
function doAlert(s) {
alert(s);
}
function jumpTo(tag) {
self.location=tag;
}
</SCRIPT>
<APPLET CODE="inJava.class"
NAME="myApplet" MAYSCRIPT
HEIGHT=400 WIDTH=100>
</APPLET>
<P>
<A NAME="JUMP">jump here from JAVA via JAVASCRIPT</A>
</BODY>
</HTML>
Matt Humphrey

2008-01-18, 8:18 am


"bH" <bherbst65@hotmail.com> wrote in message
news:72c83caf-4abe-40c6-8811-0891ed749888@l1g2000hsa.googlegroups.com...
> Hi All,
>
> I am . Given the two codings below:
> the Applet and the JavaScript, is it correct to say that
> the Applet is calling the Javascript or the Javascript is
> calling the Applet?
>
> Your help is appreciated.
>
> bH
>
> import java.applet.*;
> import java.net.*;
>
> public class inJava extends Applet{
> public void init(){
> String msg1 = "We will jump to an HTML tag";
> String msg2 =
> "http://www.extension.iastate.edu/gif/Balls/l_green.gif";
> try {
> getAppletContext().showDocument
> (new URL("java script:doAlert(\"" + msg1 +"\")"));
> getAppletContext().showDocument
> (new URL("java script:jumpTo(\"" + msg2 +"\")"));
> }
> catch (MalformedURLException me) { }
> }
> }
>
>
> <HTML><HEAD></HEAD><BODY>
> <SCRIPT>
> function doAlert(s) {
> alert(s);
> }
> function jumpTo(tag) {
> self.location=tag;
> }
> </SCRIPT>
> <APPLET CODE="inJava.class"
> NAME="myApplet" MAYSCRIPT
> HEIGHT=400 WIDTH=100>
> </APPLET>
> <P>
> <A NAME="JUMP">jump here from JAVA via JAVASCRIPT</A>
> </BODY>
> </HTML>


I didn't test this--I'm assuming it works for you. I don't see any place
where JavaScript calls the applet--the applet is simply embedded in the HTML
The applet could loosely be said to be calling JavaScript, although it is
through the applet context, the browser and the browser's ability to execute
the javascript protocol in a URL. Not all browsers (or all versions of all
browsers) support showDocument, even fewer will handle JavaScript in a URL
and those that remain may be subject to popup blocking.

Matt Humphrey http://www.iviz.com/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com