Java ve Javascript
Javadan javascripte ve Javascriptten java ya aktarılan değerler
Applet içerisinden Javascripte erişen Kod
String msg = "Hello from Java (using javascript alert)";
try {
getAppletContext().showDocument(new URL("javascript:doAlert("" + msg +"")"));
}
catch (MalformedURLException me) { }
try {
getAppletContext().showDocument(new URL("javascript:doAlert("" + msg +"")"));
}
catch (MalformedURLException me) { }
Appletin olduğu sayfadaki Javascript Kodu
<HTML><HEAD></HEAD><BODY>
<SCRIPT>
function doAlert(s) {
alert(s);
}
</SCRIPT>
<APPLET CODE="InJava4.class"
NAME="myApplet" MAYSCRIPT
HEIGHT=10 WIDTH=10>
</APPLET>
</BODY>
</HTML>
<SCRIPT>
function doAlert(s) {
alert(s);
}
</SCRIPT>
<APPLET CODE="InJava4.class"
NAME="myApplet" MAYSCRIPT
HEIGHT=10 WIDTH=10>
</APPLET>
</BODY>
</HTML>
Javascript üzerinden Applete erişen kod:
<html>
<script language="Javascript">
function accessAppletMethod()
{
document.AppletABC.appendText('welcome to mkyong dot com');
}
</script>
<head><title>Testing</title></head>
<body onload="accessAppletMethod()">
<h1>Javascript acess Applet method</h1>
<applet width=300 height=100 id="AppletABC"
code="com.mkyong.applet.JavaScriptToJava.class">
</applet>
</body>
</html>
<script language="Javascript">
function accessAppletMethod()
{
document.AppletABC.appendText('welcome to mkyong dot com');
}
</script>
<head><title>Testing</title></head>
<body onload="accessAppletMethod()">
<h1>Javascript acess Applet method</h1>
<applet width=300 height=100 id="AppletABC"
code="com.mkyong.applet.JavaScriptToJava.class">
</applet>
</body>
</html>
Javascriptin eriştiği applet
package com.mkyong.applet;
import java.applet.Applet;
import java.awt.FlowLayout;
import java.awt.TextArea;
public class JavaScriptToJava extends Applet{
TextArea textBox;
public void init(){
setLayout(new FlowLayout());
textBox = new TextArea(5,40);
add(textBox);
}
public void appendText(String text){
textBox.append(text);
}
}
import java.applet.Applet;
import java.awt.FlowLayout;
import java.awt.TextArea;
public class JavaScriptToJava extends Applet{
TextArea textBox;
public void init(){
setLayout(new FlowLayout());
textBox = new TextArea(5,40);
add(textBox);
}
public void appendText(String text){
textBox.append(text);
}
}
Yorumunuzu Ekleyin