Results 1 to 4 of 4

Thread: Java/Javascript

  1. #1
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default Java/Javascript

    I wanna create a simple Java/javascript applet.

    I mean: An Java-applet who can call a javascript function in his html document.

    HTML-document:
    Java Code:
    <html>
    <head>
    <script type="text/javascript">
    function theJFunction()
    {
     alert("Hello world");
    }
    </script>
    </head>
    <body>
    
    <applet code="myApplet" width="500" height="500"></applet>
    </body>
    </html>
    Applet:
    Java Code:
    public class myApplet extends java.applet.Applet
    {
     public void init()
     {
      //here to call the javascript function "theJFunction()"
     }
    }
    How can I call the javascript function from my applet?

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

  3. #3
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default

    I've allready seen that document but when I do
    Java Code:
    getAppletContext().showDocument
            (new URL("javascript:doAlert(\"" + msg +"\")"));
          }
    The page goes to another URL, I mean the browser thinks the page goes to another URL.
    And than I can't use the javascript command "onbeforeunload".

    For the JSObject I don't have the libraries, and I can't find where to download them.

  4. #4
    JaVal is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Default

    In order to start using JSObject you need to import netscape.javascript.JSObject
    Add plugin.jar to the classpath of you project, netscape is there.
    Plugin.jar can be found in jre6 folder

Similar Threads

  1. javascript + java
    By karq in forum JavaServer Pages (JSP) and JSTL
    Replies: 10
    Last Post: 10-19-2010, 10:40 PM
  2. java communicating with javascript
    By sunyi000 in forum New To Java
    Replies: 12
    Last Post: 08-10-2010, 07:44 AM
  3. HonoGenerate for Java,jsp,html,javascript,css
    By jaapnap in forum Reviews / Advertising
    Replies: 0
    Last Post: 12-05-2009, 11:56 PM
  4. JSON from javascript to java servlet
    By boss-tech in forum Java Servlet
    Replies: 1
    Last Post: 09-18-2009, 08:27 AM
  5. JavaScript to Java Statement
    By mutuah in forum Advanced Java
    Replies: 0
    Last Post: 08-08-2007, 05:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •