admin管理员组文章数量:1336632
I have a JavaScript function which is:
function printreceipt(tax,subtotal,total)
{
subtotalElem=document.getElementById("total");
var taxElem=document.getElementById("tax");
productElem=document.getElementById("product-name");
alert("here are my products" + taxElem.innerHTML + subtotalElem.innerHTML);
}
How to send JavaScript variables to Java applet?
I have a JavaScript function which is:
function printreceipt(tax,subtotal,total)
{
subtotalElem=document.getElementById("total");
var taxElem=document.getElementById("tax");
productElem=document.getElementById("product-name");
alert("here are my products" + taxElem.innerHTML + subtotalElem.innerHTML);
}
How to send JavaScript variables to Java applet?
Share Improve this question edited Apr 12, 2012 at 12:04 Andrew Thompson 169k41 gold badges222 silver badges436 bronze badges asked Apr 12, 2012 at 11:41 Rose WanguiRose Wangui 211 silver badge3 bronze badges3 Answers
Reset to default 5Your applet should have a public method , for example receiveData() :
public void receiveData(String dataFromJS)
{
//Do what you need with your data
}
Let's say you have something like that in your web page :
<applet id ="appletID" name="myApplet" ... ></applet>
In your javascript you just have to call the applet public method like this :
var myApp = document.applets['myApplet'];
myApp.receiveData(taxElem.innerHTML + subtotalElem.innerHTML);
The previous example will send the taxElem and subtotalElem content to the applet.
To send data from Applet to JS you sould use JSObject in your applet
You can use netscape.javascript.JSObject for Java-to-JS direction or reference the applet by its id for JS-to-Java.
See here for detailed example : http://rostislav-matl.blogspot./2011/10/java-applets-building-with-maven.html
The most reliable way to do this is to open a new page with the parameters encoded in the URL, then write those parameters as into an applet element as param
elements. (Though +1 to each of the other answers.)
本文标签: How to send JavaScript variables to Java appletStack Overflow
版权声明:本文标题:How to send JavaScript variables to Java applet - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742399254a2467550.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论