Can a java applet manipulate the HTML page containing it?

孤街浪徒 提交于 2019-11-28 05:54:05

问题


I wanted to know if I can write something on the HTML page containing my Java applet from within the applet.

More generally, what interactions are possible between these two?

Thanks.


回答1:


From within your java applet

 // object to allow applet to invoke Javascript methods
protected static JSObject appletWindowJSObject = null;

appletWindowJSObject = JSObject.getWindow(this);

 //Call your javascript method on the page and pass it something
 appletWindowJSObject.call("myJavascriptMethod", "This is what I am passing");

You can then use javascript to manipulate the html page as usual.

May also need to include the mayscript parameter when declaring the applet, not sure if this is needed anymore or not.




回答2:


You could use the JSObject.

Sun: java to javascript communication




回答3:


A java applet can call javascript functions.



来源:https://stackoverflow.com/questions/1176198/can-a-java-applet-manipulate-the-html-page-containing-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!