Question

Calling java script from java applet

Asked by: hansol1

Hi
Suppose this is my java program.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class testscript extends Applet
{
 Button btest;
 public void init()
  {
    try
      {
        btest=new Button("Test HjavaScript");
       }
      catch( Exception e){
      System.out.println(e);
       }
   }

public void start()
   {
}

public boolean handleEvent(Event e) {
      
            
       if((e.id==Event.ACTION_EVENT) ||(e.target==btest))//||(e.target==btest)))
       {
            String msg=new String("Hi Gaurav");
      }
}
}


this is my java script
<HTML>
<HEAD>


<SCRIPT LANGUAGE="JavaScript">
<!-- Beginning of JavaScript -


function MsgBox (textstring) {
alert (textstring) }


// - End of JavaScript - -->
</SCRIPT>


</HEAD>
</html>
How I will call java script function MsgBox from java applet program.I call this function on button click of the java program.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-12-12 at 01:16:23ID20823862
Tags

javascript

Topics

Java Programming Language

,

New to Java Programming

Participating Experts
1
Points
100
Comments
23

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. applet call applet
    How do I call an applet in another applet in 2 different package ?
  2. java applet
    Is there away to target a new window in java applet?? In html i would use <a href="http.www.this.test"tartget=new>test</a>
  3. Java to JavaApplet
    Hi, I made a minesweeper game in java. I want to take that and turn that into a web based applet. My questions is - how do I do so? If you need this - here is the source of the main class: import javax.swing.*; import javax.imageio.*; import java.awt.image.*; import java...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: TimYatesPosted on 2003-12-12 at 01:23:21ID: 9926905

Add this method to your applet class:

  // Cool reflection based javascript calling method
  // Taken from http://www.rgagnon.com/javadetails/java-0172.html
  public String callBrowser( String jsCmd )
  {
    String jsResult = null ;
    boolean success = false ;
    try
    {
      Method getw = null, eval = null ;
      Object jswin = null ;

      /* does it in IE too */
      Class c = Class.forName( "netscape.javascript.JSObject" ) ;

      Method ms[] = c.getMethods() ;
      for( int i = 0 ; i < ms.length ; i++ )
      {
        if( ms[ i ].getName().equals( "getWindow" ) )
          getw = ms[ i ] ;
        else if( ms[ i ].getName().equals( "eval" ) )
          eval = ms[ i ] ;
      }

      Object a[] = new Object[ 1 ] ;

      a[ 0 ] = this ; /* this is the applet */
      jswin = getw.invoke( c, a ) ; /* this yields the JSObject */

      a[ 0 ] = jsCmd ;
      Object result = eval.invoke( jswin, a ) ;

      if( result instanceof String )
        jsResult = (String)result ;
      else
        jsResult = result.toString() ;

      success = true ;
    }
    catch( InvocationTargetException ite )
    {
      jsResult = "" + ite.getTargetException() ;
    }
    catch( Exception e )
    {
      jsResult = "" + e ;
    }

    if(success)
      return jsResult ;
    else
    {
      System.out.println( "eval failed with error " + jsResult ) ;
      return null ;
    }
  }

then, call the method with:

callBrowser( "MsgBox( '" + msg + "' )" ) ;

(make sure your applet is in the same HTML as the javascript

Tim

 

by: hansol1Posted on 2003-12-12 at 02:01:19ID: 9927154

hi
program is not giving the alert message in internet explorer.I am using the first example give in the your link .
thanks
gaurav

 

by: TimYatesPosted on 2003-12-12 at 02:04:01ID: 9927168

Post your applet source code, and your HTML (and any exceptions you are getting in the Java Console)

Tim

 

by: hansol1Posted on 2003-12-12 at 02:59:06ID: 9927383

as i said you,i used the first example given in your link
////java code
import java.applet.*;
import java.net.*;

public class inJava extends Applet{
  public void init(){
    String msg = "We will jump to an HTML tag";
    try {
      getAppletContext().showDocument
        (new URL("javascript:doAlert(\"" + msg +"\")"));
      getAppletContext().showDocument
        (new URL("javascript:jumpTo(\"#JUMP\")"));
      }
    catch (MalformedURLException me) { }
    }
  }

//html page
HTML><HEAD></HEAD><BODY>
<SCRIPT>
function doAlert(s) {
   alert(s);
   }
function jumpTo(tag) {
   self.location=tag;
   }
</SCRIPT>
<APPLET CODE="inJava.class"
        NAME="myApplet"  MAYSCRIPT
        HEIGHT=400 WIDTH=10>
</APPLET>
<P>
<A NAME="JUMP">jump here from Java via Javascript</A><br>
</BODY>
</HTML>
 



Netscape AND Microsoft

thanks

 

by: hansol1Posted on 2003-12-12 at 04:57:46ID: 9927881

hi
A java script function return type is String.how I handle that function in java apllet.
I try with this.
in java
line=getAppletContext().showDocument(new URL("javascript:setText(\"' +line+'\")"));
here line is of type String.in javascript it is like this.
function getText()
{
      return document.getElementById("UserText").value;
}
But it is giving error in java.How i get return value.
thanks

 

by: TimYatesPosted on 2003-12-12 at 05:36:54ID: 9928060

use the code I posted, not the first example from the link....that first example sucks :-(

-----------------

public class inJava extends Applet
{
  public void init()
  {
    System.out.println( callBrowser( "getText()" ) ) ;
  }

  public String callBrowser( String jsCmd )
  {
    String jsResult = null ;
    boolean success = false ;
    try
    {
      Method getw = null, eval = null ;
      Object jswin = null ;

      /* does it in IE too */
      Class c = Class.forName( "netscape.javascript.JSObject" ) ;

      Method ms[] = c.getMethods() ;
      for( int i = 0 ; i < ms.length ; i++ )
      {
        if( ms[ i ].getName().equals( "getWindow" ) )
          getw = ms[ i ] ;
        else if( ms[ i ].getName().equals( "eval" ) )
          eval = ms[ i ] ;
      }

      Object a[] = new Object[ 1 ] ;

      a[ 0 ] = this ; /* this is the applet */
      jswin = getw.invoke( c, a ) ; /* this yields the JSObject */

      a[ 0 ] = jsCmd ;
      Object result = eval.invoke( jswin, a ) ;

      if( result instanceof String )
        jsResult = (String)result ;
      else
        jsResult = result.toString() ;

      success = true ;
    }
    catch( InvocationTargetException ite )
    {
      jsResult = "" + ite.getTargetException() ;
    }
    catch( Exception e )
    {
      jsResult = "" + e ;
    }

    if(success)
      return jsResult ;
    else
    {
      System.out.println( "eval failed with error " + jsResult ) ;
      return null ;
    }
  }
}

-------------------

<HTML><HEAD></HEAD>
<BODY>
  <SCRIPT>
    function getText()
    {
         return document.getElementById("UserText").value;
    }
  </SCRIPT>
  <APPLET CODE="inJava.class"
                NAME="myApplet"  MAYSCRIPT
                HEIGHT=400 WIDTH=10>
  </APPLET>
  <br>
  <div id="UserText">Woo woo!!</div>
  <!-- div may be this...can't remember -->
  <div name="UserText">Woo woo!!</div>
</BODY>
</HTML>

 

by: hansol1Posted on 2003-12-12 at 06:19:30ID: 9928328

hi tim
I am bit confused with callbrowser function.
I am not getting what is going on.
I make you clear that ,In javascript I have to function.In one function,I am passing one String argument and in another function I have to receive the String value.

function setText(myText)
{
      document.getElementById("TextEditor").innerHTML=document.getElementById("TextEditor").innerHTML+"<br>"+myText;
}

function getText()
{
      return document.getElementById("UserText").value;
}

how I will use these function in javascript.
what I get ,for returning function is that,inside callbrowser function you are receiving value in result.Is I am right?
Please  tim,try to understabd me.I don't know javascript.
thanks

 

by: hansol1Posted on 2003-12-12 at 06:40:54ID: 9928468

hello TimYates

I get the callbrowser function.
what will i do for passing String value to the javascript.
function setText(myText)
{
     document.getElementById("TextEditor").innerHTML=document.getElementById("TextEditor").innerHTML+"<br>"+myText;
}
for the above function.
thanks

 

by: TimYatesPosted on 2003-12-12 at 06:42:12ID: 9928474

> what will i do for passing String value to the javascript.

callBrowser( "setText( 'some text' )" ) ;

:-)

 

by: hansol1Posted on 2003-12-12 at 07:28:13ID: 9928766

TimYates
I have some problem.if you try to help me.I am not gettin about the callbrowser.Is it system defined  or user defined.PLease try to help me timYates.
I am posted here my full program with comments.Hope you will understand.
java file:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.Socket;
import javax.swing.*;
import java.net.*;
import java.io.*;
import java.awt.TextField;

/*<applet code="support" width=450 height=260>
<param name=host value ="100.100.7.27">
<param name=port1 value="8888">
</applet>*/

public class Csupport extends Applet implements Runnable
{
    Button sendData;
    boolean  ClientStatusmsg;
   Thread t;
    byte[]linebuffer=new byte[3000];
   
   OutputStream opst,opstchat;
   String opratName;
    String outputData;
    String outputDatatemp;
   String msgconnect;
   InputStream   ipst;
   Socket  sock;
    String oprttyping;
    String host1,port1;
   int len;
   
  public void init()
  {
    try
      {
        sendData=new Button("Send");
                          
        add(sendData);
      sendData.setEnabled(false);
      ClientStatusmsg=false;
      host1=getParameter("host");
       port1=getParameter("port1");
      
      }
     catch(Exception e){
      System.out.println(e);
       }
   }

  public void start()
   {
    try
      {
      int port=8888;
      String sdg=new String();
      linebuffer = new byte[3000];
      System.out.println("Port Value Start" +port1);
      System.out.println("host Value Start" +host1);      
      sock=new Socket("100.100.7.27",8888);
      //sock=new Socket("65.61.162.30.",8888);
      opst =sock.getOutputStream();
          t = new Thread(this);
          t.start();
       sdg="CASE2001:^~%";
      sdg=sdg+host1 +"@#";
      System.out.println("Data from sdg"+ sdg);
        len=sdg.length();
          linebuffer=sdg.getBytes();
          if(len>linebuffer.length-1)
        len = linebuffer.length-1;
      opst.write(linebuffer, 0, len+1);
      opst.flush();
      }//end of try
      catch(Exception e) {
     //userChat.appendText("applet error: "+e+"\n");
    }//end of catch
  }//end of start function
   

//function to get input data
 public void run()
  {
      String temp = new String();
      String temp2=new String();
      String temp1;
      outputData=new String();
      outputDatatemp=new String();
      
      byte []buf1=new byte[3000];
       try
      {
      //ipst.reset();
       ipst = sock.getInputStream();
            byte[] buf = new byte[3000];
            while(true)
            {
               int avail = ipst.available();
                if(avail<1) avail=1;
                if(avail>buf.length)
                  {
                     avail=buf.length;
                  }

                  int bytes_read = ipst.read(buf,0,avail);
                  int j = 0;
                  int i;

                  for( i=0; i<=bytes_read; i++)
                  {
                         buf[j++] = buf[i];
                  }
                        
                  temp1 = new String(buf,0,0, j);
                  temp2 = temp2 + temp1;
                  temp2=temp2.trim();

                  System.out.println("temp1 :" +temp1);

                  if(j>bytes_read)
                  {
                        System.out.println("temp2="+temp2);
                        temp.trim();
                        System.out.println("temp :" +temp);
                        if(temp1.length()>3)
                        {
                              //int hh=temp1.indexOf (0,10);
                              outputData=temp1.substring(0,10);
                              outputDatatemp=temp2.substring(0,11);
                              System.out.println("outputData:" +outputData);
                              System.out.println("outputData:" +outputDatatemp);
                        //opratName.substring(
                              
                              
                  //Message when operator accept the chat

                        if((outputData.equals("ASE1007:~^"))||(outputDatatemp.equals("CASE1007:~^")))
                        {
                              String accp_msg=new String();
                              int pp=temp1.indexOf ("{",0);
                              String  tempoprtname=new String();
                              //pp=Integer.parseInt(output);
                              System.out.println(pp);
                              accp_msg=temp1.substring(10,pp-1);
                              int txtlen=accp_msg.length();
                              txtlen=txtlen+18;
                              int pp2=temp1.indexOf ("$",txtlen);
                              tempoprtname=temp1.substring(txtlen,pp2);
                              opratName=tempoprtname;
                              System.out.println("outputDataoperator name" + tempoprtname);
                              System.out.println("opratName name" + tempoprtname);
                              msgconnect=accp_msg +":" + tempoprtname;
                              System.out.println("Accept Message"+msgconnect);
                              try {
                                          getAppletContext().showDocument
                                      (new URL("javascript:setText(\"" + msgconnect+"\")"));
                                    System.out.println("Accept Message"+msgconnect);
                                          }
                                        catch (MalformedURLException me) {System.err.print(me); }
                                        
                              //dsend.setEnabled(true);
                                    sendData.setEnabled(true);
                                    //userText.setEditable(true);
                                    temp1=" ";
                                    outputData=" ";
                                    temp2=" ";
                                    msgconnect=" ";
                                    tempoprtname=" ";
                        }
                        
                        System.out.println("OutputData22" + outputData);

                        // start chattin
                        if((outputData.equals("ASE1011:~^"))||(outputDatatemp.equals("CASE1011:~^")))
                        {
                              String strTemp=new String();
                              String strColor=new String();
                              
                              System.out.println("temp1 in ASE1011"+ temp1);
                              
                              int pp=temp1.indexOf ("^",0);
                              int lp=temp1.length();
                              System.out.println("Value of P is "+pp);
                              strTemp=temp1.substring(pp+1,lp);
                              System.out.println("Chat data to send html"+strTemp);
                              //here I have to send strTemp data in javasript function
                              try {
                                          getAppletContext().showDocument
                                      (new URL("javascript:setText(\"" + strTemp+"\")"));
                                          System.out.println("Chat data to send html"+strTemp);
                                          }
                                        catch (MalformedURLException me) {System.err.print(me); }
                                        
                              //strTemp="";
                              temp1="";
                              outputData="";
                              temp2="";
                              strTemp="";
                        }
                        
                        
                  }//end of temp length if
                  }//end of outer if
                  }//END OF WHILE
            
            //System.out.println("TempValue:"+temp);
        
      } catch(Exception e) {

           System.err.print(e);
    }
  }
      
 


/////////////////////////////////////////////////////////////
//handle mouse event to click on button
      
      public boolean handleEvent(Event e) {
      
            
       if((e.id==Event.ACTION_EVENT) && (e.target==sendData))//||(e.target==userText)))
       {
            
            byte[]linebuffer=new byte[3000];
            String ClientChat="CASE2002:^~#%";
            String line =new String();//= getText;
//here I have to receive the value.
            /*try {
                  //line=getAppletContext().showDocument(new URL("javascript:setText(\"' +line+'\")"));
                  }
                catch (MalformedURLException me) {System.err.print(me);}*/
                if(line.length()>0)
                {
            System.out.println("Value of line " +line);
            line=port1+": "+line;
            ClientChat=new String(ClientChat+opratName+"~!"+host1+"~!"+line+"{}") ;
            
            System.out.println("Value to send"+ClientChat);
            //userChat.appendText(">>"+line+"\n");
            System.out.println("Value to sendcheck exception"+ ClientChat);
             int len = ClientChat.length();
            linebuffer=ClientChat.getBytes();
            
            if(len>linebuffer.length-1)
            len = linebuffer.length-1;
            linebuffer[len]='\n';
            System.out.println("Hello");
            try {
                  //opst=sock.getOutputStream();
                  System.out.println("in trytest");
                    opst.write(linebuffer, 0, len);
                  opst.flush();
                  } catch(Exception ex) {

              System.err.print(ex);
      
                  }
            
            //userText.setText("");
            ClientChat=" ";      
            line="";
          }//end of String length if
            }//end of if
      
            return false;
       }//end of function
}
      //trap cursor foucs
      
  Please Tim try to help me.
thanks



                     



                   

 

by: hansol1Posted on 2003-12-12 at 07:37:05ID: 9928844

I am gettin this error for gettext function.
java.net.MalformedURLException: unknown protocol: javascriptOutputData22
eval failed with error== netscape.javascript.JSException: MAYSCRIPT is not enabled for this applet
null
eval failed with error== netscape.javascript.JSException: MAYSCRIPT is not enabled for this applet
null

 

by: TimYatesPosted on 2003-12-12 at 07:57:49ID: 9928997

> eval failed with error== netscape.javascript.JSException: MAYSCRIPT is not enabled for this applet

MAKE SURE  you have "MAYSCRIPT" in your applet tag:

<APPLET CODE="inJava.class" NAME="myApplet" HEIGHT="400" WIDTH="10" MAYSCRIPT></APPLET>

You did before...have you taken it out?

 

by: TimYatesPosted on 2003-12-12 at 07:59:31ID: 9929013

> I am not gettin about the callbrowser.Is it system defined  or user defined.

It is a method...  put it in your main Csupport Applet class  like I did in my "inJava" example...

Tim

 

by: TimYatesPosted on 2003-12-12 at 08:00:38ID: 9929026

the callBrowser function just uses reflection to call a piece of javascript in the same HTML as the applet :-)

You can do it without reflection, but then you need to add java40.jar to the classpath when you compile, as the compiler will not be able to find the JSObject class otherwise...

That's why it's easier to use reflection :-)

Tim

 

by: hansol1Posted on 2003-12-12 at 08:20:54ID: 9929188

java.net.MalformedURLException: unknown protocol: javascript
getting this error
Please give me for both function.String return type with argument and void reurn type with String argument.

 

by: TimYatesPosted on 2003-12-12 at 08:29:21ID: 9929244

>  java.net.MalformedURLException: unknown protocol: javascript

What are you doing?  That's not an error from my code...

are you still doing showDocument() ?

Get rid of it...

Just use callBrowser()...

CHANGE:
-----------------

                         try {
                                    getAppletContext().showDocument
                                 (new URL("javascript:setText(\"" + msgconnect+"\")"));
                              System.out.println("Accept Message"+msgconnect);
                                    }
                                  catch (MalformedURLException me) {System.err.print(me); }
                                 

TO
-----------------

                         callBrowser( "setText( '" + msgconnect + "' )" ) ;

(make sure you have added the callBrowser method to your applet class)

Tim

 

by: TimYatesPosted on 2003-12-12 at 08:31:22ID: 9929258

> Please give me for both function.String return type with argument and void reurn type with String argument.

I have shown you twice already...

void return type, string argument:
---------------------------------------
callBrowser( "setText( 'Hello' )" ) ;

string return type, string argument:
---------------------------------------
String s = callBrowser( "getText( 'Hello' )" ) ;

string return type, no argument:
---------------------------------------
String s = callBrowser( "getText()" ) ;

 

by: TimYatesPosted on 2003-12-12 at 08:32:16ID: 9929266

The callBrowser method (again) that you need to add to your applet class is:

--------------------------------

public String callBrowser( String jsCmd )
  {
    String jsResult = null ;
    boolean success = false ;
    try
    {
      Method getw = null, eval = null ;
      Object jswin = null ;

      /* does it in IE too */
      Class c = Class.forName( "netscape.javascript.JSObject" ) ;

      Method ms[] = c.getMethods() ;
      for( int i = 0 ; i < ms.length ; i++ )
      {
        if( ms[ i ].getName().equals( "getWindow" ) )
          getw = ms[ i ] ;
        else if( ms[ i ].getName().equals( "eval" ) )
          eval = ms[ i ] ;
      }

      Object a[] = new Object[ 1 ] ;

      a[ 0 ] = this ; /* this is the applet */
      jswin = getw.invoke( c, a ) ; /* this yields the JSObject */

      a[ 0 ] = jsCmd ;
      Object result = eval.invoke( jswin, a ) ;

      if( result instanceof String )
        jsResult = (String)result ;
      else
        jsResult = result.toString() ;

      success = true ;
    }
    catch( InvocationTargetException ite )
    {
      jsResult = "" + ite.getTargetException() ;
    }
    catch( Exception e )
    {
      jsResult = "" + e ;
    }

    if(success)
      return jsResult ;
    else
    {
      System.out.println( "eval failed with error " + jsResult ) ;
      return null ;
    }
  }

 

by: TimYatesPosted on 2003-12-12 at 08:32:34ID: 9929269

AND make sure you have put MAYSCRIPT in the applet tag on the HTML page

 

by: hansol1Posted on 2003-12-12 at 23:03:58ID: 9933292

Thanks a lot tim.Please help once again.
the return value I am not gettin g.It is giving undefined.I am using in this way.
in java
String d=new String();      
          d=( callBrowser( "getText()" ) ) ;
      System.out.println("return value"+d);
in java script
function getText()
    {
      var s = "PP";
         return s;
    }
other call browser function is the same.I am getting the result of  void return type, string argument:
One more thing Tim,when ever I change in java file,i doesn't reflect on html file,until I recompile java file in different name .why this problem occur.I am using IE5.
Thanks.Once again.

 

by: hansol1Posted on 2003-12-13 at 00:17:20ID: 9933481

Why this error is coming
eval failed with error== com.ms.com.ComFailException: Could not complete the operation due to error 80020101.
thanks

 

by: hansol1Posted on 2003-12-13 at 00:38:28ID: 9933613

PLease help me on my lasr two comment

 

by: hansol1Posted on 2003-12-13 at 01:48:56ID: 9933749

I failed to get return value from java script.Please refer my third last comment.It is returning a String "Undefined"

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...