applet interfaces with javascript in IE

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
LVL 2
TorusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vladi21Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TorusAuthor Commented:
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
vladi21Commented:
try another ways

look at URLs
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

TorusAuthor Commented:
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
vladi21Commented:
please try
Q & A - Communicating with JavaScript
http://www.inquiry.com/techtips/java_pro/answer.asp?pro=java_pro&docID=1819
0
vladi21Commented:
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
vladi21Commented:
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
TorusAuthor Commented:
oh! IE4+ VM has JSOBJECT.Class. Thanks.
0
vladi21Commented:
it was first line in my first comment :)
0
TorusAuthor Commented:
oh! yes, sorry, I just concentrate the URL and your example.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.