Talking to applets with JavaScript

I got asked recently "how do you get JavaScript to access the methods of a Java applet?"

Seeing as though, at the time, I was "learning" Java and always hate to have to say "I don't know" - I set about finding out. It turns out it isn't half as hard as you might imagine.

Before we start, let's look at an example. The yellow box below is a simple applet that contains just a label and a text box. Use the select box (HTML) below it to update your favourite colour.

My favourite colour is:

How does this work? Technically I think it is something to do with a Netscape invention called LiveConnect, but I won't bore you with that.

The first thing to do is create a public method in your applet that performs the actions you require. The applet above uses this code:

public void setMessageText(String message) {
txtMessage.setText( "You chose: " + message.toUpperCase() );

That is the hard part. Yep, that's it! All you need to do now is to create a JavaScript call to this method via the applet object. Like this:

document.applets[0].setMessageText('This text came from JavaScript');

The only other thing you need to do is add the "MAYSRIPT" attribute to the applet's tags so that is allows JavaScript to tell it what to do.

Now you may well be thinking - "What use is that!?" Wait, the possibilities are almost endless. For a start, applets can use CORBA/IIOP connections to the server to go and fetch data, not only from Domino servers. No more need to submit the document to get data from the server ;-)

All you need to do now is get up to scratch with Java applets so that you can start creating your own applets. I've attached the source file (.java) for you take a look at, but this is VERY basic. For more help you best bet is to do a search on the usual sites.

Other sources:


    • avatar
    • Philippe Desrochers
    • Fri 12 Jul 2002

    from lotus script

    Hi, if you want to use with an agent made in lotus script you should do this :

    1) copy your field from the agent to the form. ex: Call docTemp.CopyAllItems(docStat) docStat.Form = "fHistogramme" Call workspace.EditDocument(False, docStat, True)

    2) add the applet on the form (create menu) Note : the applet must have to get the parameters values in the init methot. Ex: public void init() { ... String str_temp; str_temp = getParameter("text"); ....

    3) Add the parameters and the values (fields) in lotus at the applet's parameter values. Note : the name of the parameter must be the same in the applet. (here, the parameter's name in lotus is "text")

    Philippe Desrochers

    1. lotus script

      I am a student in washington computer Accadmy doing computer hard ware engineering.I need a lecture note in Lotus script and Lotus administrator. Thank you Emmanuel T.Kamara

  1. Applet JavaScript LiveConnect

    Hi Eventhough I have implemented these sort of functionality, this seems to be too nice. Especially most of them won't believe You could transfer /get values between Applet and JavaScript without submitting a JSP/Html page. this pretty Cool .

    More than that this site seems to be pretty Nice that delevers technology.

    Why Can't You Bring up an applet ie that use a import java.FileChooser.* that does the file Upload ? that could help people to do a Buld UpLoad ?

    Great Site !

    Thanks Jackson

    1. Re: Applet JavaScript LiveConnect

      If u use java.io.FileChooser and get files to applet then how u going to upload those file to document??

      Any idea..

  2. How do I send Values from Applet to JavaScript


    Sorry to ask How do I send Values from Applet to JavaScript

    COuld some one help me

    Thanks James

    1. Re: How do I send Values from Applet to JavaScript

      Don't be sorry to ask just be sorry no to have searched the site more thoroughly ;o)

      The article you are looking for [<a href="unid/DOMM-4UTFCP?OpenDocument">is here</a>]...

      Jake -codestore.net

    • avatar
    • Sam
    • Tue 11 Jul 2006


    "The only other thing you need to do is add the "MAYSRIPT" attribute to the applet's tags so that is allows JavaScript to tell it what to do. "

    MAYSRIPT should be MAYSCRIPT. Good article though :)

    • avatar
    • jaipal
    • Tue 1 May 2007

    neat trick

    didn't know this was possible.. thanks

  3. Applet in Notes Client

    How can I make an applet load in the Notes Client?

  4. Applet doesn't work on Firefox

    Hi Jake,

    Here I have a problem. Your applet doesn't work on Firefox, but works on IE. Do you have any idea of what happend?

    Thanks a lot

    It rise this error (horrible):


    cargar: clase SimpleApplet.class no encontrada.

    java.lang.ClassNotFoundException: SimpleApplet.class

    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)

    at java.lang.ClassLoader.loadClass(Unknown Source)

    at java.lang.ClassLoader.loadClass(Unknown Source)

    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)

    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)

    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)

    at java.lang.Thread.run(Unknown Source)

    Caused by: java.io.IOException: open HTTP connection failed:http://www.codestore.net/store.nsf/area/area/67CB4D15E50B305C862569FC003FBD7C/$FILE/SimpleApplet/class.class

    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)

    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)

    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)

    at java.security.AccessController.doPrivileged(Native Method)

    ... 7 more

    Excepci├│n: java.lang.ClassNotFoundException: SimpleApplet.class

    • avatar
    • udaybits246@gmail.com
    • Tue 8 Dec 2009

    Using JavaScript How to check whether an applet is loaded or not???

    thanks in advance

    • avatar
    • Rajeev
    • Tue 11 May 2010

    how can i execute the javaapplets using javascripts. In a browser i have javaapplet and i need to execute this using javascripts.. how can i do this??

    any suggestions or sample code for javascripts to run javaapplets

    • avatar
    • Nebbian
    • Sat 15 May 2010

    How to execute the javaapplets using javascripts:


Your Comments


Navigate other articles in the category "Java"

« Previous Article Next Article »
None Found   Recreate LotusScript Print method in Java

About This Article

Author: Jake Howlett
Category: Java
Keywords: applet; javascript; java;


SimpleApplet.class (2 Kbytes)
SimpleApplet.java (1 Kbytes)


Print Friendly

Let's Get Social

About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »