Sending/returning a string from a Java Applet to JavaScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bary W Pollack

    Sending/returning a string from a Java Applet to JavaScript

    Is it possible to have a Java Applet that is running on a web page to send/return a string (or an int) so that some JavaScript that is running on the same webpage can retrieve the information? If so, HOW?

    Thanks!

    -Bary-


  • Laurent Bugnion, GalaSoft

    #2
    Re: Sending/returning a string from a Java Applet to JavaScript

    Hi,

    Bary W Pollack wrote:[color=blue]
    > Is it possible to have a Java Applet that is running on a web page to
    > send/return a string (or an int) so that some JavaScript that is running
    > on the same webpage can retrieve the information? If so, HOW?
    >
    > Thanks!
    >
    > -Bary-[/color]

    If the browser supports LiveConnect (IE and Netscape do), then it is
    possible. See
    <URL: http://www.galasoft-LB.ch/myjavascript/consulting/LiveConnect102>
    and
    <URL: http://www.galasoft-LB.ch/myjavascript/consulting/LiveConnect130>

    Laurent
    --
    Laurent Bugnion, GalaSoft
    Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
    Private/Malaysia: http://mypage.bluewin.ch/lbugnion
    Support children in Calcutta: http://www.calcutta-espoir.ch

    Comment

    • George Maydwell

      #3
      Re: Sending/returning a string from a Java Applet to JavaScript

      On Fri, 1 Aug 2003 01:10:12 -0700, "Bary W Pollack"
      <bpollack@sierr anevada.edu> wrote:
      [color=blue]
      >Is it possible to have a Java Applet that is running on a web page to send/return a string (or an int) so that some JavaScript that is running on the same webpage can retrieve the information? If so, HOW?
      >
      >Thanks!
      >
      >-Bary-[/color]

      This is very easy to do. The Java applet needs a public method which
      returns a String and all Javascript has to do is call it. Here's The
      Modern CA Author Javascript which does this in a setting with frames
      where the applet may not even exist:
      var mutatedRule = 'Press the "Test CA" button first'
      var d = parent.frames["view"].document
      var applet = d.applets[0]
      if (applet) {
      mutatedRule = applet.getRuleC urrentMutation( )
      }

      Here's what the Java method looks like:
      public synchronized String getRuleCurrentM utation() {
      return RuleExport.toSt ring(rule, rule.mutated != null ?
      rule.mutated : rule.unmutated) ;
      }


      George Maydwell
      --
      Modern Cellular Automata: www.collidoscope.com/modernca
      Collidoscope Hexagonal Screensaver: www.collidoscope.com

      Comment

      Working...