最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to send JavaScript variables to Java applet - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 5

Your 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.)

发布评论

评论列表(0)

  1. 暂无评论