zaterdag 19 december 2015
Calling Java from Javascript and Calling Javascript from Java
This little sample shows that we can call javascript doAlert from Java.
Also we show that calling the function display will be received in Java with
data from Javascript.
applet.java
import java.applet.*;
import java.net.*;
public class applet extends Applet{
public void init(){
Display("start of java");
}
public void Display(String txt){
try{
getAppletContext().showDocument(new URL("javascript:doAlert(\""+txt+"\")"));
}catch(Exception e){}
}
}
index.html
<HTML>
<SCRIPT>
function doAlert(s) {
alert(s);
}
</SCRIPT>
<APPLET CODE="applet.class" NAME="applet" MAYSCRIPT >
</APPLET>
<INPUT type="button" value="Java.Display" onClick="document.applet.Display('hi')">
</HTML>
Labels:
java,
javascript
Abonneren op:
Reacties posten (Atom)
Geen opmerkingen:
Een reactie posten