1

I have been wondering if there is a way to make the following javascript functions work in IE8 and Chrome:

var funct = function()
{
var ppt = new java.awt.Point(200,100);
alert(ppt.x);
} 

This thing works only in Firefox. Is there a way to enable global Java packages in IE 8 and Chrome?

10
  • 1
    How is this supposed to work in FireFox? Commented Nov 1, 2010 at 10:12
  • You create a script in an html file open firefox and run the script. That is how it is supposed to work ... and it does. Commented Nov 1, 2010 at 10:13
  • I was amazed to find that "java" in Firebug returns a "JavaObject". And new java.awt.Point actually works. No idea why, can't find much on Google. Commented Nov 1, 2010 at 10:14
  • Well, of course it does, because there is java support in firefox. That makes a programmer's task quite easy. However, in order to actually use the same functionality in IE8 and Chrome, I would have to create an applet and through it expose the necessary functions...how messy... Commented Nov 1, 2010 at 10:16
  • 2
    It's exactly like the fact IE browsers support client side VBScript while no other browser does. Each browser and its own little (or big) tricks.. IMO it's a mistake to depend on such a thing and nowadays even Microsoft themselves recommend against using client side VBScript as it's not cross browser. Bottom line, better find "pure" JavaScript equivalent for what you need. :) Commented Nov 1, 2010 at 10:21

2 Answers 2

2

Not quite answering your question - but you might find GWT (http://code.google.com/webtoolkit/) helpful.

It lets you write web applications in Java, which gets 'compiled' into javascript to be run inside any modern browser. It only supports a subset of the standard Java libraries - in particular it doesn't support java.awt.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, dear Ian, however GWT won't do me any good for a couple of reasons: 1. I have been using it for 2 years now and it doesn't contain the functionality I need. 2. What I'm trying to achieve shouldn't be allowed on any browser! 3. I have good intentions, but even I am scared of what I achieved and of the possibilities it opens...
hehehe just what are your intentions? - are you hoping to access files on the user's system?
lol that would be too easy... Actually what I am doing is using a java applet, so that I can invoke its functions using javascript. However, the java applet itself uses JNA (java native access) to invoke some native stuff. At the end of the day what you get is javascript invoking native functions. Here is a schematics of the thing:::: javascript - > java - > native (user32, gdi32, etc...)
0

Well, here it is. IE 8 and Chrome do not allow for global java packages: i.e you cant use java.lang.String, or java.atw.Point directly in your javascript. However, if you have an applet, you can easily expose such classes through your applet. For example, if you import java.awt.Point in your applet and have a method like this:

public Point createPoint(int x,int y);

You should be able now from your javascript to access the applet and just call its method like this:

(javascript code)

var applet = document.getElementById("applettie");
var Point = applet.createPoint(20,30);
//now you have the Point object 

Cheers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.