JavaScript to Java Nightmare

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

    JavaScript to Java Nightmare

    I've searched over and over again and have not been able to find a
    definitive answer.

    Basically, we have a heavily JavaScripted web site. What I was hoping
    to do was to start enhancing our site by calling some Java functions
    via JavaScript.

    I have tried every sample I could find on the net and none of them
    works with Mozilla or Explorer. I've read 4 or 5 books on Java and
    JavaScript programming and none of the code in them works any longer
    in regards to calling Java functions from JavaScript.

    Is there a way to do this? If so, how can I do it, and do it in such a
    way that users will be able to use their preferred browser (Explorer,
    Mozilla, or Safari)?

    Does anyone know of a sample web site that still works that shows how
    to accomplish this?

    Thanks in advance for any help!
  • Thomas 'PointedEars' Lahn

    #2
    Re: JavaScript to Java Nightmare

    Steve W wrote:
    [color=blue]
    > I have tried every sample I could find on the net and none of them
    > works with Mozilla or Explorer. I've read 4 or 5 books on Java and
    > JavaScript programming and none of the code in them works any longer
    > in regards to calling Java functions from JavaScript.[/color]

    "Doesn't work" is an insufficient and therefore a useless error description.
    What have you tried? What did you expect? What happened?
    [color=blue]
    > Is there a way to do this? If so, how can I do it, and do it in such a
    > way that users will be able to use their preferred browser (Explorer,
    > Mozilla, or Safari)?[/color]




    HTH

    PointedEars

    Comment

    • Steve Weintraut

      #3
      Re: JavaScript to Java Nightmare

      Sorry, I should have posted more detail. Here is some sample code and a
      better explanation.

      You can look at the code below. It will work just fine using Win32
      Mozilla, But it doesn't work using Internet Explorer on XP, and it also
      doesn't work on any OS X based browser (Mozilla, Safari, Explorer).

      So I guess the issue here is........is there a way to call java
      functions in
      javascript that will work in most current browser versions on both
      platforms rather than just Mozilla on Windows?????

      At the very least, getting it to work on Win32 explorer as well as Win32
      mozilla would at least be a start

      In my case, here is a simple HTML page with JavaScript, along with an
      applet in Java code.

      Except in Mozilla on Win32, every other browser basically tells me that
      the function "GetData" is not a function or "Object doesn't support this
      property or method"

      But once again, in Mozilla Win32 it works....the question is how do I
      get
      it to work on Explorer Win32 and at least one OS X browser

      Thanks in advance for any help......

      Steve

      HTML Code
      ------------------------------------------------------------
      <HTML>
      <HEAD>
      <TITLE>Simple Applet Example</TITLE>
      <SCRIPT>
      function GetName()
      {
      var myApplet=docume nt.getElementBy Id("FMLinker")
      alert(myApplet. name)
      alert(myApplet. GetData())
      }

      </SCRIPT>
      </HEAD>
      <BODY>
      <applet code="FMLinker. class" name="FMLinker" width=300
      height=150 id="FMLinker" scriptable="tru e" mayscript="true ">
      Your browser does not support Java, so nothing is displayed.
      </applet>
      <form name="myForm" method="post" action="">
      <input type="button" name="Button" value="Button"
      onClick="GetNam e()">
      </form>
      </BODY>
      </HTML>

      Java Code (i stripped out a bunch of code just to get to the simplest
      case)
      -------------------------------------------------------------
      ---------------------------------------

      import java.applet.*;
      import java.net.*;
      import java.awt.*;
      import java.sql.*;

      public class FMLinker extends Applet
      {
      public void init()
      {
      System.out.prin tln("Hello, Java!");
      System.out.prin tln(GetData());
      }

      public String GetData()
      {
      String myResultString= "haha";
      return myResultString;
      }
      }




      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Laurent Bugnion, GalaSoft

        #4
        Re: JavaScript to Java Nightmare

        Hi,

        Steve Weintraut wrote:
        [color=blue]
        > Sorry, I should have posted more detail. Here is some sample code and a
        > better explanation.
        >
        > You can look at the code below. It will work just fine using Win32
        > Mozilla, But it doesn't work using Internet Explorer on XP, and it also
        > doesn't work on any OS X based browser (Mozilla, Safari, Explorer).
        >
        > So I guess the issue here is........is there a way to call java
        > functions in
        > javascript that will work in most current browser versions on both
        > platforms rather than just Mozilla on Windows?????
        >
        > At the very least, getting it to work on Win32 explorer as well as Win32
        > mozilla would at least be a start
        >
        > In my case, here is a simple HTML page with JavaScript, along with an
        > applet in Java code.
        >
        > Except in Mozilla on Win32, every other browser basically tells me that
        > the function "GetData" is not a function or "Object doesn't support this
        > property or method"
        >
        > But once again, in Mozilla Win32 it works....the question is how do I
        > get
        > it to work on Explorer Win32 and at least one OS X browser
        >
        > Thanks in advance for any help......
        >
        > Steve
        >
        > HTML Code[/color]

        <snipped>

        You can see working examples, including source code, at
        <URL: http://www.galasoft-LB.ch/myjavascript/consulting/LiveConnect102>
        and
        <URL: http://www.galasoft-LB.ch/myjavascript/consulting/LiveConnect130>

        This should allow you to test in different environments, and to find out
        if maybe your system is configured in a way which doesn't allow applets
        to be scripted, for example.

        HTH,

        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

        Working...