?
Solved

applet interfaces with javascript in IE

Posted on 1999-12-14
10
Medium Priority
?
327 Views
Last Modified: 2013-12-29
I know that in netscape, there is JSObject that can use applet to interface with javascript. How about IE? Can applet interfaces with it.
If so, how?
Thanks
0
Comment
Question by:Torus
  • 6
  • 4
10 Comments
 
LVL 7

Accepted Solution

by:
vladi21 earned 90 total points
ID: 2279800
IE4+ support JSObject

it must help

Calling JavaScript
http://www.inquiry.com/techtips/java_pro/10MinuteSolutions/CallingJavaScriptFromJava.htm

Interfacing with JavaScript
http://www.buttontool.com/helpjscript.html

NetscapeWorld - Calling Java Applets from JavaScript
http://www.netscapeworld.com/nw-05-1997/nw-05-jjscript.html

The JavaScript Security Model in Communicator 4.x
http://developer.netscape.com/docs/manuals/communicator/jssec/index.htm

Netscape's JavaScript vs. Microsoft's JScript
http://www.javacats.com/US/articles/Jsart.html
__
Launching an HTML document from an applet
--
you need to use the showDocument and AppletContext, but there is a little thing. If you are
using both the browser Netscape and IE then you sure need to do something in addition.
 add "MAYSCRIPT" in the <applet> tag
to let IE understand that you are asking the browser to do something.
This is because the JavaScripts are netscapes production, and other browser needs to know that
there will be some browser interaction.

The code:

[Java applet]

import java.applet.*;
import java.net.*;

public class inJava extends Applet{
  public void init(){
    String msg = "We will jump to a URL, you can further make that when
clicked in list or so, it goes to the URL as done in next line of code";
    try {
      getAppletContext().showDocument
        (new URL("javascript:doAlert(\"" + msg +"\")"));
      getAppletContext().showDocument
 (new  URL("javascript:jumpTo(\"http://java.sun.com\")"));
      }
    catch (MalformedURLException me) { }
    }
  }
 



[Javascript and HTML]

<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>
</BODY>
</HTML>

0
 
LVL 2

Author Comment

by:Torus
ID: 2282622
It didn't work in IE(4.01). Exception is raised.

java.net.MalformedURLException: unknown protocol: javascript
      at java/net/URL.<init> (URL.java)
      at java/net/URL.<init> (URL.java)
      at test.actionPerformed (test.java:29)
      at java/awt/Button.processActionEvent (Button.java)
      at java/awt/Button.processEvent (Button.java)
      at java/awt/Component.dispatchEventImpl (Component.java)
      at java/awt/Component.dispatchEvent (Component.java)
      at java/awt/EventDispatchThread.run (EventDispatchThread.java)
0
 
LVL 7

Expert Comment

by:vladi21
ID: 2283034
try another ways

look at URLs
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 2

Author Comment

by:Torus
ID: 2283488
1 and 5 URL can't access. 3 and 4 are not revalent to java calling
javascript in IE. In 2, i don't understand using the call action.
Any examples?
0
 
LVL 7

Expert Comment

by:vladi21
ID: 2283529
please try
Q & A - Communicating with JavaScript
http://www.inquiry.com/techtips/java_pro/answer.asp?pro=java_pro&docID=1819
0
 
LVL 7

Expert Comment

by:vladi21
ID: 2283575
import java.awt.*;
import java.applet.*;
import java.net.*;

public final class JavaScript extends Applet {
  Button urlButton, jsobjectButton;

  public void init() {
    urlButton = new Button("JavaScript URL test()");
    jsobjectButton = new Button("JSObject test()");

    add(urlButton);
    add(jsobjectButton);
  }

  public boolean action(Event event, Object arg) {

    if(event.target == urlButton) {
      URL url;

      try {
          url = new URL("javascript:top.test();");
          getAppletContext().showDocument(url);
      } catch(MalformedURLException e) {
          e.printStackTrace();
      }
    } else if(event.target == jsobjectButton) {

        //if(System.getProperty("java.vendor").toLowerCase().startsWith("netscape"))
        {
              netscape.javascript.JSObject window;

              window = netscape.javascript.JSObject.getWindow(this);
              window = (netscape.javascript.JSObject)window.getMember("top");
              window.eval("test();");
      }
    } else
      return false;

    return true;
  }
}

Its work fine in my IE5
netscape.javascript.*
u can find in
Program Files\Netscape\Communicator\Program\Java\Classes\java40.jar

or in ie packages
0
 
LVL 7

Expert Comment

by:vladi21
ID: 2283705
also look the same
at
Call Javascript from a Java applet
a)Netscape only
b)Netscape AND Microsoft Internet Explorer v4+
http://ada.tactika.com/realhome/jsht/javas-j1.html#f3

so now u can submit answer :)
0
 
LVL 2

Author Comment

by:Torus
ID: 2285891
oh! IE4+ VM has JSOBJECT.Class. Thanks.
0
 
LVL 7

Expert Comment

by:vladi21
ID: 2286168
it was first line in my first comment :)
0
 
LVL 2

Author Comment

by:Torus
ID: 2286254
oh! yes, sorry, I just concentrate the URL and your example.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month3 days, 9 hours left to enroll

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question