js 调用applet方法

JavaScript014

js 调用applet方法,第1张

1、函数声明为public

后台代码(把public改成protected也可以)

public string ss()

{

return("a")

}

2、在html里用 <%=fucntion()%>可以调用

前台脚本

<script language=javascript>

var a = " <%=ss()%>"

alert(a)

</script>

一般的浏览器中是无法通过js调用本地java程序的,但是可以调用嵌入到网页的applet的方法。交互方式如下:

<applet codebase = "." width = "400" height  = "400"

  name= "MyApplet" code = "test.applets.MyApplet1.class"> 

<script>

// js访问applet属性:document.appletName.appletField (属性必须是public的) 

// js访问Applet方法:document.appletName.appletMethod (方法必须是public的)

function showLable{

     // 调用test.applets.MyApplet1类的invokeByJS方法 

     document.applets["MyApplet"].invokeByJS('myvalue')

}

</script>