Call applet methods from Javascript

Hello,
If I call applet method like :
function callbackFunc(){
    var pp = appletID.getData();
    alert(pp);
It works only if applet is deployed with <APPLET> tag or with javascript.
If applet is deployed using <Object> and <embed> tags, in browser console the error is :
TypeError: appletID.getData is not a function
I couldn't find why is that behaviour. What do I do wrong?
Thanks

Hi Paul,
(1)Seems to be your Java Runtime Environment path is still setted for JRE 1.3.0_01 and not for 1.3.1. So pelase go to the
Control Panel-->java plugin 1.3.1-->Advanced. Here you set the Java Runtime Environment to the JRE 1.3.1 version. Its better to remove the older version before installing the new version on JRE.
(2)<OBJECT> tag won't work for Netscape. You can only use <APPLET> or <EMBED> tag for Netscape.
Hope this will help you.
Anil
Developer Technical Support
Sun Microsystems
http://www.sun.com/developers/support

Similar Messages

  • Call Applet method from JavaScript, tiny test program works... SOMETIMES!?

    I have an embedded Applet in a web page, and I am trying to directly call a method in that Applet from the same page, using JavaScript.
    Here is the complete Applet:
    import java.applet.Applet;
    public class Test extends Applet {
      public String test() {
        return "test() method return value";
    }Here is the complete web page:
    <HTML>
    <HEAD><TITLE>Applet Invocation test</TITLE></HEAD>
    <BODY>
    <APPLET CODE="Test" WIDTH=10 HEIGHT=10 NAME="test"></APPLET>
    <HR>
    <SCRIPT>
    document.write( "JavaScript is working<br>" );
    document.write( document.test.test() );
    </SCRIPT>
    </BODY>
    </HTML>Is there anything wrong with this? Because it works about 15% of the time, displaying an <HR>, "JavaScript is working", and then "test() method return value" on the next line.
    The other 85% of the time, it just gets to "JavaScript is working", then I get a JavaScript error "Object does not support this property or method" for the line: document.write( document.test.test() );
    Now here's another weird quirk... I can get it to work ALL the time, if I delay the execution of the Applet method. For example, if the first line after <SCRIPT> is alert( "alert" ); then the user gets a little dialog box with "alert" message in it, and when they hit OK execution continues, and the applet method call ALWAYS works. (On a side note, if I make the Applet test() method static, it NEVER works. Why is this?)
    So it seems to me, that when it is failing, it is because the Applet is not completely loaded into the browser yet. My question is, how can I get around this?? Is there a way to instruct JavaScript to wait until the Applet is finished loading before attempting to call any methods on it?
    PS I am using Windows ME and IE 6

    Thanks for the reply, I appreciate it. I have another question, if you don't mind... here is what my new test web page looks like:
    <HTML>
    <HEAD>
    <TITLE>Applet Invocation test</TITLE>
    <SCRIPT>
    function testFunc()
      document.write( document.test.test() );
    </SCRIPT>
    </HEAD>
    <BODY onLoad="testFunc()">
    <APPLET CODE="Test" WIDTH=10 HEIGHT=10 NAME="test">
    </APPLET>
    <HR>
    </BODY>
    </HTML>What happens is: the page loads, I see a 10x10 grey applet box, and a <HR>... then a split second later, onLoad is fired, and everything on the page so far is REPLACED with the output of testFunc(), so the ONLY thing on the page after this all completes is "test() method return value"
    Why is a single document.write() statement CLEARING the page before outputting? I don't understand. If calling a document.write() from an onLoad event wipes out everything on the page, this is not extremely helpful solution.

  • Invoking Applet methods from Javascript for Netscape 6

    Hi,
    I am trying to invoke an applet method from javascript, but it is failing with Netscape 6 browser:
    I am doing it the following way-
    function test(form)
    var i = document.myapplet.getname();
    where myapplet is the name of the applet and getname is a method within the applet. This is
    working with Ie but not with netscape 6.
    I would appreciate it if someone could tell me how should I invoke the applet method for netscape browsers.
    Thanks.
    Jay Srin.

    Not working with NS 6 - and will not i guess till they upgrade to Mozilla Version 1.0 - Live Connect is not implemented 100% correct yet - if you want you can download the 7.0 Pre Release Netscape - since its using mozilla 1.0 it should work , see :
    http://forum.java.sun.com/thread.jsp?forum=30&thread=272975

  • Call to Applet Method from JavaScript Failed.

    I Am calling a method from a javascript function from within a web page.
    The page is loaded into a frame. The parent window of the frame has stored a reference to the applet which defines the methods. Note I am treating the reterence to the applet as a global variable. So that I can reference it methods as I navigate from one page to another.
    I have JavaScript objects defined, and I am passing them as parameters to the applet's methods. In java, the JavaScript objects are refererenced as JSObject. When I call a java method passing a JavaScript
    Object I get the following exception. Note Iam using j2sdk1.4.2_01 on a Windows 2000 Professional System. This problem start occurring after the recent Microsoft Worm/Virus a fix was loaded on my system which resulted in the following bug. Could someone please help me.
    java.lang.NullPointerException
         at sun.plugin.javascript.ocx.JSObject.setIExplorerAppletContext(Unknown Source)
         at sun.plugin.com.DispatchImpl.convertParams(Unknown Source)
         at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
         at sun.plugin.com.DispatchImpl$2.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.plugin.com.DispatchImpl.invoke(Unknown Source)
    java.lang.Exception: java.lang.NullPointerException
         at sun.plugin.com.DispatchImpl.invokeImpl(Unknown Source)
         at sun.plugin.com.DispatchImpl$2.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.plugin.com.DispatchImpl.invoke(Unknown Source)

    A little code snippet would help. I use JSObjects from Java 1.4 no problem and do have all the latest updates. I also have JavaScript calling Java code as well - also with no problem.

  • Call Java method from JavaScript

    Hi,
    I have a Java class called abc.java and in that I have a method called assignValue(String value).
    I need to call this method, assignValue() , from JavaScript.
    Is there a way to call a Java method from JavaScript.
    Any help is greatly appreciated.
    Thanks.

    Yes I did, and I still don't get it, I have created a JSF web application, not an applet, as I posted earlier my code to executes sit's in a class file, not an applet file.
    My Page1.class file is as follows
    * Page1.java
    package a1;
    import ....
    public class Page1 extends AbstractPageBean {
        public void valset(int val) {
    }my jsp file "Page1.jsp" is as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <jsp:root version="1.2" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:ui="http://www.sun.com/web/ui">
        <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
        <f:view>
            <ui:page binding="#{Page1.page1}" id="page1">
                <ui:html binding="#{Page1.html1}" id="html1">
                    <ui:head binding="#{Page1.head1}" id="head1">
                        <ui:link binding="#{Page1.link1}" id="link1" url="/resources/stylesheet.css"/>
                    </ui:head>
                    <ui:body binding="#{Page1.body1}" id="body1" style="-rave-layout: grid">
                        <ui:form binding="#{Page1.form1}" id="form1">
    <applet code="Page1.class" name="Page1" width="1100" height="600">
                    </applet>
                            <ui:button action="#{Page1.button1_action}" binding="#{Page1.button1}" id="button1" onMouseOver="form1.Page1.valset(1);"
                                style="left: 239px; top: 192px; position: absolute" text="Button"/>
    </ui:form>
                    </ui:body>
                </ui:html>
            </ui:page>
        </f:view>
    </jsp:root>All I get is a grey box the size of the applet window. Could you please let me know what I'm doing wrong?

  • Call C# method from javascript in WebView and retrieve the return value

    The issue I am facing is the following :
    I want to call a C# method from the javascript in my WebView and get the result of this call in my javascript.
    In an WPF Desktop application, it would not be an issue because a WebBrowser
    (the equivalent of a webView) has a property ObjectForScripting to which we can assign a C# object containg the methods we want to call from the javascript.
    In an Windows Store Application, it is slightly different because the WebView
    only contains an event ScriptNotify to which we can subscribe like in the example below :
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    this.webView.ScriptNotify += webView_ScriptNotify;
    When the event ScriptNotify is raised by calling window.external.notify(parameter), the method webView_ScriptNotify is called with the parameter sent by the javascript :
    function CallCSharp() {
    var returnValue;
    window.external.notify(parameter);
    return returnValue;
    private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
    var parameter = e.Value;
    var result = DoSomerthing(parameter);
    The issue is that the javascript only raise the event and doesn't wait for a return value or even for the end of the execution of webView_ScriptNotify().
    A solution to this issue would be call a javascript function from the webView_ScriptNotify() to store the return value in a variable in the javascript and retrieve it after.
    private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
    var parameter = e.Value;
    var result = ReturnResult();
    await this.webView.InvokeScriptAsync("CSharpCallResult", new string[] { result });
    var result;
    function CallCSharp() {
    window.external.notify(parameter);
    return result;
    function CSharpCallResult(parameter){
    result = parameter;
    However this does not work correctly because the call to the CSharpResult function from the C# happens after the javascript has finished to execute the CallCSharp function. Indeed the
    window.external.notify does not wait for the C# to finish to execute.
    Do you have any solution to solve this issue ? It is quite strange that in a Window Store App it is not possible to get the return value of a call to a C# method from the javascript whereas it is not an issue in a WPF application.

    I am not very familiar with the completion pattern and I could not find many things about it on Google, what is the principle? Unfortunately your solution of splitting my JS function does not work in my case. In my example my  CallCSharp
    function is called by another function which provides the parameter and needs the return value to directly use it. This function which called
    CallCSharp will always execute before an InvokeScriptAsync call a second function. Furthermore, the content of my WebView is used in a cross platforms context so actually my
    CallCSharp function more look like the code below.
    function CallCSharp() {
    if (isAndroid()) {
    //mechanism to call C# method from js in Android
    //return the result of call to C# method
    } else if (isWindowsStoreApp()) {
    window.external.notify(parameter);
    // should return the result of call to C# method
    } else {
    In android, the mechanism in the webView allows to return the value of the call to a C# method, in a WPF application also. But I can't figure why for a Windows Store App we don't have this possibility.

  • Call Java Method From JavaScript Function

    hi everyone
    i need a help in calling Java method from a javaScript method
    ex:
    function confirmAddRecord() {
    cHours =document.getElementById('frmP:ChargeHours').value;
    cSTime =document.getElementById('frmP:ChargeStartTime').value;
    var answer = confirm("Are you sure you want to add Record?")
    if (answer){
    here i want to call the Java Method that is located in session bean that takes the upper params cHours & cSTime
    else{
    return false;
    i know i can do it as an action button but it is required me to be in that way can any one help plz
    Message was edited by:
    casper77

    That depends on the nature of your parameters. I guess you calculate the params on client and then want to submit them. In this case and if you don't want to use Ajax simple add some <input type="hidden"> elements (of course there correspondend components dependent of your framework) and store the params there. If the javascript isn't invoked by a button click, you can use a button nevertheless. Set visible="false" and call
    document.getElementById('client_id_of_my_hidden_button').click();
    (or maybe doClick() dependent on your framework).

  • Call applet method with javascript

    my html - code:
    <APPLET NAME="Mail" ... ... ></APPLET>
    <form action="javascript:document.applets("Mail").test("Execute JAVA Applet Function")">
    <input type="submit" value="Execute Applet Function">
    </form>
    my applet code:
    public void test(String t)
    {System.out.println("executing test()");
    teststr = t;
    repaint();
    in the paint() method i draw the teststr with Graphics.drawString - but nothing happens...
    any suggestions?
    thx

    Directly calling a Java Applet's public method from within
    JavaScript is made possible by LiveConnect which is not implemented by Internet Explorer as of yet. LiveConnect is only available on Netscape navigator at this time.

  • Problem calling Java method from JavaScript in JSP / ADF

    Hi all,
    In my JavaScript onMouseUp() function, I need to call a method on my Java backing bean. How is this done? Info on the web indicates a static Java method can be called by simply "package.class.staticMethod(...)". but when I put the statement
    "jsf.backing.GlobalRetriever.createBasemap(affectedLayer);"
    I get an error message "jsf is undefined".
    The functionality I'm trying to get is: I have a custom slider control and based on its value, I want to call oracle map viewer specifying a map extent of the (current extent / slider value) to do a zoom in/out. In addition, the slider uses a onMouseMove() function to change the size of the image display so it looks like a dynamic zoom in/out.
    Please assist or let me know if I can provide some additional information. Thanks in advance.
    Jim Greetham

    No. The Java and Javascript in a Faces application are really working in two different universes.
    Java is running on the server. It generates HTML (and sometimes even Javascript) and sends that to the client machine. That's where all your backing beans are.
    Javascript runs directly in the browser. There's no way anything on the server can have access to anything you define in Javascript, unless you explicitly send that information back to the server, either via standard form submission (which only works when someone presses a "Submit" button) or via an Ajax-type call. So otherwise, nothing you define in Javascript will ever be available to a backing bean.

  • Call Applet method from C++. Possible ?

    Hi,
    For all the guru's of JNI and applets...
    I have a (C++) ATL object and an applet in an HTML page in IE 6.0
    Is it possible to invoke a public method of the applet from the ATL object ? ( without involving any Javascript / liveconnect )?
    If so how?
    Basically I'm searching for a workaround to a bug
    http://developer.java.sun.com/developer/bugParade/bugs/4838960.html
    As per the bug evaluation it is caused due to "Pumping messages while
    JavaScript->Java call is being executed"
    Thus I want to somehow send the info directly to java and bypass the Javascript->Java call.
    desparate.....
    TIA
    mqs

    Hi,
    For all the guru's of JNI and applets...
    I have a (C++) ATL object and an applet in an HTML
    page in IE 6.0
    Is it possible to invoke a public method of the applet
    from the ATL object ? ( without involving any
    Javascript / liveconnect )?
    If so how?Yes it is. You create the JVM (a method of the jni)
    ,and then you run the method of the applet on the jvm.
    For the details
    there is a book about the Java Native interface free
    of charge in the sun's website.
    >
    Basically I'm searching for a workaround to a bug
    http://developer.java.sun.com/developer/bugParade/bugs/
    838960.html
    As per the bug evaluation it is caused due to
    "Pumping messages while
    JavaScript->Java call is being executed"
    Thus I want to somehow send the info directly to java
    and bypass the Javascript->Java call.
    desparate.....
    TIA
    mqs

  • Accessing Signed Applet Method From Javascript

    Hi All,
    In my intranet application i have to retrive the mac addres of the client using the applet. I have to capture the MAC Address and set it as a hidden value in the jsp page.
    I have used the signed applet and able to retrive the mac address of the client using IE but I am not able to do the same on NN 7.1
    Below is my javascript and the applet tag syntax, please help me if i am wrong anywhere
    function mac()
    var mval=document.myApplet.getWinMACAddress()
    alert("addres" +mval)                         
    document.loginform.js_value.value=mval
    and the applet tag in my jsp page is
    <applet code ="SignedAppletDemo.class" codebase="http://mysouthasia/AcadResource/jsp/" archive="SSignedApplet.jar" width=1 height=1 align=center name="myApplet" >
    </applet>
    Thanks in Advance

    Since getWinMACAddress( ) seems to work just fine for IE, is there an equivalent for NN7.1?
    What happens if I run Opera instead, and on a Linux system? Or Safari on OS X? Obviously getWinMACAddress( ) isn't going to work for that.
    I really don't understand why so many Asian programmers get "Find the MAC address of..." as a homework assignment. There are many reasons why it isn't really practical to do so, and for examples, just search this forum for MAC addresses. Lots and lots of examples and counter examples.

  • Help with calling java functions from javascript

    I am using javax.script to interpret javascript from a java applet. it loads the js file into a string, and then does engine.eval(script_string). My question is, how would I make functions in the class file that are available to javascript?
    Update: Instead of that, I am loading a js script that will contain all of the usable functions. Here it is:
    //core.js for Javasphere 0.31
    var pkgs = new JavaImporter(java.lang, java.lang.System, java.awt);
    with(pkgs) {
    function Abort(msg) {
            var graph = new Graphics();
            g = graph.getgraphics();
            g.drawString(msg, 20, 20);
    }When I do engine.eval("Abort(\"something\")"); it throws this error:
    javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: error instantiating (0): class java.awt.Graphics is interface or abstract (<Unknown source>#8) in <Unknown source> at line number 8

    Eggbertx, let's start from scratch if you don't mind. Say you have this Applet
    pubic class MyApplet extends Applet
      String message;
      //CALL THIS METHOD FROM JAVASCRIPT
      public void setMessage(String msg)
        message = msg;
        // this saves you from having
        // to call getGraphics() from JavaScript
        repaint();
      public void paint(Graphics g)
        g.drawString(message, 10, 30);
    }Then in your HTML file you may have something like this:
    <input type="text" id="msg" value=""></input>
    <input type="button" value="Set Message" onclick="setAppletMessage()"></input>
    <applet id="myApplet" code="MyApplet.class" width="400" height="100"></applet>And in the JavaScript file:function setAppletMessage()
      var msg = document.getElementById("msg").value;
      document.myApplet.setMessage(msg);
    }This is about all you really need to do. See how the Graphics object is no longer in your .js file?
    Note: You may run into other difficulties in getting this code to work because of browser, security, or some other pain-in-the-neck issues, but this is the idea.
    Eggbertx, I see you added a star to my first post and I think you should take that off because:
    1. <tt>Component</tt> is abstract... so you can not call the <tt>new</tt> operator.
    2. The call <tt>component.getGraphics()</tt> is not going to work either, because <tt>component</tt> was never created.

  • How to call a bean method from javascript event

    Hi,
    I could not find material on how to call a bean method from javascript, any help would be appreciated.
    Ralph

    Hi,
    Basically, I would like to call a method that I have written in the page java bean, or in the session bean, or application bean, or an external bean, from the javascript events (mouseover, on click, etc...) of a ui jsf component. I.e., I would like to take an action when a user clicks in a column in a datatable.
    Cheers,
    Ralph

  • Accessing a public method from javascript in an applet!!!

    Hi!!
    I'm have an applet (named say applet.class) in an html page that has a public method like this....
    public void doShowFrame()
              Frame frame = new frame();
         frame.setVisible (true);
    What I want to do is to call that method with javascript, I've tried to do it like this...
    function show(){
    applet.doShowFrame();
    But when i press the button that launch the java scipt the browser says
    'applet' is unidentified...
    What's wrong, what can I do??

    http://www.google.com/search?q=applet+javascript+communication&sourceid=opera&num=0&ie=utf-8&oe=utf-8
    how hard was that? seriously.

  • How to call jpf controller method from javascript

    Can any one help me how to call pageflow controller method from JavaScript.\
    Thanks.

    Accessing a particular pageflow method from Javascript is directly not possible unless we do some real funky coding in specifying document.myForm.action = xyz...Heres what I tried and it did not work as expected: I found another workaround that I will share with you.
    1. In my jsp file when I click a button a call a JavaScript that calls the method that I want in pageflow like this: My method got invoked BUT when that method forwards the jsp, it lost the portal context. I saw my returned jsp only on the browser instead of seeing it inside the portlet on the page of a portal. I just see contents of jsp on full browser screen. I checked the url. This does make the sense. I do not see the url where I will have like test1.portal?_pageLabe=xxx&portlet details etc etc. So this bottom approach will notwork.
    document.getElementById("batchForm").action = "/portlets/com/hid/iod/Batches/holdBatch"; // here if you give like test1.portal/pagelable value like complete url...it may work...but not suggested/recommended....
    document.getElementById("batchForm").submit;
    2. I achieved my requirement using a hidden variable inside my netui:form tag in the jsp. Say for example, I have 3 buttons and all of them should call their own action methods like create, update, delete on pageflow side. But I want these to be called through javascript say for example to do some validation. (I have diff usecase though). So I created a hidden field like ACTION_NAME. I have 3 javascript functions create(), update() etc. These javascripts are called onclick() for these buttons. In thse functions first I set unique value to this hiddent field appropriately. Then submit the form. Note that all 3 buttons now go to same common action in the JPF. The code is like this.
    document.getElementById("ACTION_NAME").value = "UPDATE";
    document.getElementById("batchForm").submit.
    Inside the pageflow common method, I retriev this hidden field value and based on its value, I call one of the above 3 methods in pageflow. This works for me. There may be better solution.
    3. Another usecase that I want to share and may be help others also. Most of the time very common usecase is, when we select a item in a drop bos or netui:select, we want to invoke the pageflow action. Say we have 2 dropdown boxes with States and Cities. Anytime States select box is changed, it should go back to server and get new list of Cities for that state. (We can get both states and cities and do all string tokenizer on jsp itself. But inreality as per business needs, we do have to go to server to get dynamic values. Here is the code snippet that I use and it works for all my select boxes onChange event.
    This entire lines of code should do what we want.
    <netui:anchor action="selectArticleChanged" formSubmit="true" tagId="selectPropertyAction"/>                    
    <netui:select onChange="document.getElementById(lookupIdByTagId('selectPropertyAction',this )).onclick();" dataSource="pageFlow.selectedArticleId" >
    <c:forEach items="${requestScope.ALL_ARTICLE}" var="eachArticle">
    <%-- workshop:varType="com.hid.iod.forms.IoDProfileArticleRelForm" --%>
    <netui:selectOption value="${eachArticle.articleIdAsString}">${eachArticle.articleItemName}</netui:selectOption>
    </c:forEach>               
    </netui:select>
    See if you can build along those above lines of code. Any other simpler approches are highly welcome.
    Thanks
    Ravi Jegga

Maybe you are looking for

  • Can axis categories be graphics instead of text

    I have a requirement to display images as my horizontal categories for a simple bar chart. I see that you can overload a label display function to produce the string you want - but my question is is there a way to use an image in place of a label as

  • IMac 27" as external under windows

    Hello there, I just bought a rMBP and wish to conect it to my 2011 27" iMac, everything works under OS X, but if I try it under windows it won't recognize the iMac at all (this is with thunderbolt). Is there anyway I could use windows 7 (in the macbo

  • Firmware 1.0.1 is out.

    just installed it via iTunes. no idea what it does.

  • I have been taking notes on my ipad for 2 hours. Accidently copied

    I have lost a doc i typed for 2 hours as notes when accidentally copied and cut all. But when i pressed paste an old like was pasted and my document disappeared. Can i find it in an draft/archive somewhere?

  • File - BAPI -  File Synchronous scenario

    Hi all, I am working on a 'flat file--> BAPI --> flat file' scenario. This is a synchronous scenario in which data from input flat file will be sent to BAPI on R/3 side and from the response of BAPI a flat file will be created. Is it possible to impl