Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (524)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Cross-platform/browser method to detect java plugin  (Read 4967 times)
0 Members and 1 Guest are viewing this topic.
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 78
Projects: 15


★★★★★


« Posted 2009-03-01 14:16:23 »

I was looking for a reliable way to detect if the java plugin is available on a browser, i've had a look at various javascript methods and sun's deployJava.js but they all seem a little unreliable especially on browser like safari and konqueror where no information is reported at all from javascript.

I've since found the only reliable way is to actually have a java applet launch and report back that it is available.

Thought i'd post the method here in case if it is useful to others.

java code

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
import java.applet.Applet;
import netscape.javascript.JSObject;

public class Test extends Applet {
   
   JSObject win;
   
   public void init() {
     
      win = JSObject.getWindow(this);
     
      Object[] param = { System.getProperty("java.version") };
     
      // alert javascript that java plugin is found
      win.call("javaSupported", param);
   }

}


html/javascript code
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<body onLoad="checkJava()">


<script type="text/javascript">

    var javaFound = false;

    function javaSupported(version) {
      javaFound = true;
      var gamebox=document.getElementById('appletbox');
      // remove applet
     gamebox.innerHTML = 'Java version ' + version + ' available';
    }

    function javaNotFound() {
      if (!javaFound) {
            var appletbox=document.getElementById('appletbox');
            appletbox.innerHTML = 'Java Not Found';
        }
    }

    function checkJava() {
        // wait 10 seconds if java hasn't responded presume its not found
        setTimeout('javaNotFound();', 10000);
    }
</script>

<div id="appletbox">Checking if Java Available...<applet code="Test" width="1" height="1" MAYSCRIPT/></div>

</body>
</html>


What the code does is wait 10 seconds for the applet to report back through liveconnect that it is available, if it does not report back it presumes that java is not available.

Another thing that makes this faster than using a full applet is that the innerHTML quickly removes the applet once it has reported back and avoids any further slow downs from the applet that the paint methods, etc bring. You can just change this if you are using a full applet to leave applet there instead of removing it.

example http://kappa.javaunlimited.net/temp/testjava.html

works for me on all the browsers and platforms i've tested on IE6,IE7,Opera,Safari,Firefox,Chrome, Konqueror on windows and linux.
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #1 - Posted 2009-03-01 15:05:47 »

It works, nice job.

I tried it on IE(wich ahs java)

and chrome wich doesnt sadly:(

and both gave the correct answer back.

good job
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2009-03-01 15:56:39 »

New applets grab the focus.

If you're filling a HTML form, and the applet is launches, all key events will go to the applet.

This is very confusing for the user.

It will also freeze the browser for a couple of seconds, in versions under u10.

And there are 101 liveconnect bugs.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pjt33
« Reply #3 - Posted 2009-03-01 22:37:23 »

New applets grab the focus.

If you're filling a HTML form, and the applet is launches, all key events will go to the applet.

This is very confusing for the user.

It will also freeze the browser for a couple of seconds, in versions under u10.

And there are 101 liveconnect bugs.
Including, IME.
Offline Jono
« Reply #4 - Posted 2009-03-02 00:52:59 »

It more than just freezes.. it consistently, completely crashes firefox for me. I'm not sure what the exact cause is.

That's with the 1.6.0_10-b33 plugin, running on OpenSolaris 2008.11
Offline bienator

Senior Devvie




OutOfCoffeeException


« Reply #5 - Posted 2009-03-02 02:05:44 »

http://people.fh-landshut.de/~mbien/cafebabe.html

one method uses the deployment toolkit the other via mime types. It never happened to me that both didn't work (but I haven't tested konqueror). The JavaFX deployment toolkit recently got the mimetype querie too as fallback.

Offline kappa
« League of Dukes »

JGO Kernel


Medals: 78
Projects: 15


★★★★★


« Reply #6 - Posted 2009-03-02 06:52:46 »

http://people.fh-landshut.de/~mbien/cafebabe.html

one method uses the deployment toolkit the other via mime types. It never happened to me that both didn't work (but I haven't tested konqueror). The JavaFX deployment toolkit recently got the mimetype querie too as fallback.

both methods there fail for me in opera.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2009-03-02 07:01:06 »

Yup, also fails for me in Opera.

Then I again, I never managed to get LiveConnect to work in Opera, but given the marketshare of Opera, it's not top priority for me.

Opera doesn't recognize the "javascript:" protocol either, which behaves as eval(String) in MSIE and FF.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 78
Projects: 15


★★★★★


« Reply #8 - Posted 2009-03-02 07:35:07 »

The two scripts also fail in Safari, it just goes to show the reliabilty of Suns deployment toolkit, besides it rather tedious and difficult to adjust/update the javascript each time a new browser comes out or for every browser thats out there.

However the above applet code works on both safari and opera  Grin
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 78
Projects: 15


★★★★★


« Reply #9 - Posted 2009-03-02 07:48:14 »

New applets grab the focus.
If you're filling a HTML form, and the applet is launches, all key events will go to the applet.

True but hopefully it won't be used on a page that has a html form or if it does the applet will have loaded and closed before the user has a chance to focus the html form. Besides you could probably get focus back using javascript.

It will also freeze the browser for a couple of seconds, in versions under u10.

Since this is very small class the browser freeze is smaller than that of when using a big jar and since the applet is closed before or when the init() method finishes it futher reduces the delay (thus not reaching the paint methods), however there is still a small delay just not as much as normal applets.

And there are 101 liveconnect bugs.

Yes thats true, however this method uses very little liveconnect (only one method) and most of the bugs relate to browser to plugin communication (javascript to java), this is only plugin to browser communication (java to javascript). This should hopefully avoid most of those bugs especially some of those browser specific ones (for example with firefox).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zammbi

JGO Coder


Medals: 4



« Reply #10 - Posted 2009-03-02 08:23:49 »

It works, nice job.

I tried it on IE(wich ahs java)

and chrome wich doesnt sadly:(

and both gave the correct answer back.

good job
Chrome worked for me.

Current project - Rename and Sort
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2009-03-02 08:30:23 »

True but hopefully it won't be used on a page that has a html form or if it does the applet will have loaded and closed before the user has a chance to focus the html form. Besides you could probably get focus back using javascript.
The browser freeze is so nasty, that my approach used to be to load the applet after X seconds, under the assumption that people where reading the page at that time. But, man... that did backfire.

Since this is very small class the browser freeze is smaller than that of when using a big jar and since the applet is closed before or when the init() method finishes it futher reduces the delay (thus not reaching the paint methods), however there is still a small delay just not as much as normal applets.

Unfortunately not. Even a pixel that is 1x1 px, and renders 1 color (for debugging) simply freezes the browser for up to 10 seconds on slower PCs with pre u10 Java versions.

Yes thats true, however this method uses very little liveconnect (only one method) and most of the bugs relate to browser to plugin communication (javascript to java), this is only plugin to browser communication (java to javascript). This should hopefully avoid most of those bugs especially some of those browser specific ones (for example with firefox).

You only need 1 bug, and it stops working. It's sad.

It's just that there is NO reliable way to figure out whether Java is supported in the browser, without annoying the end user.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #12 - Posted 2009-03-02 12:53:29 »

The reason I dont have java is tath I dont have admin users....

so sad.

I code on a school comp. I am gunna have to cmpy a lot of crap off when I give it back in 3 years Smiley. will take a while ot get off all of my crap, my java folder is currently 934 megabytes. that does include jdk and compilers though.

back on topic Wink

it really takes 10 seconds to load a 1x1 screen. so does a 10x10 take 100 seconds, or is it jsut the fact that is ti s a n applet.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 833
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2009-03-02 17:55:18 »

Yes, a 800x600 applet takes 1333 hours to load, never noticed?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline bienator

Senior Devvie




OutOfCoffeeException


« Reply #14 - Posted 2009-03-02 18:58:50 »

Yup, also fails for me in Opera.

Then I again, I never managed to get LiveConnect to work in Opera, but given the marketshare of Opera, it's not top priority for me.

Opera doesn't recognize the "javascript:" protocol either, which behaves as eval(String) in MSIE and FF.
i am a js noob, this was actually my first script i've written so far. Could you update it in a way that opera could interpret it without breaking it for IE and FF?

Offline bienator

Senior Devvie




OutOfCoffeeException


« Reply #15 - Posted 2009-03-02 19:17:56 »

i updated the script to use javafx deployment toolkit.

Offline kappa
« League of Dukes »

JGO Kernel


Medals: 78
Projects: 15


★★★★★


« Reply #16 - Posted 2009-03-02 19:47:01 »

i updated the script to use javafx deployment toolkit.

the javafx script work in opera now but still fails in safari.
Offline bienator

Senior Devvie




OutOfCoffeeException


« Reply #17 - Posted 2009-03-02 20:34:17 »

what do you get as result? "0 - java not enabled" or a empty box?

also could you try this page? it uses a different version of the dtfx.js

Offline kappa
« League of Dukes »

JGO Kernel


Medals: 78
Projects: 15


★★★★★


« Reply #18 - Posted 2009-03-02 20:54:31 »

what do you get as result? "0 - java not enabled" or a empty box?

I get an empty box and also same result on konqueror.

looking at the code for dtfx.js i'm very impressed with it, it is much more advance and uptodate when compared with the standard deployJava.js as it has support for much more browsers like opera and chrome.

Not sure why sun doesn't just use this script for both deployment toolkits and kill the older and less compatible deployJava.js

as for using javascript to detect java on safari, I don't think it can be done with pure javascript since the browser doesn't support it, the best that can be done is just check if it is safari and if so then just try run the applet whether java is present or not.
Offline bienator

Senior Devvie




OutOfCoffeeException


« Reply #19 - Posted 2009-03-02 21:20:24 »

Not sure why sun doesn't just use this script for both deployment toolkits and kill the older and less compatible deployJava.js
they use deployJava.js from within dtfx.js. I guess the only reason to have two scrips is simple because JavaFX development runs asynchronously and more rapidly compared to JRE development. Its easier to introduce api incompatibilities in JavaFX as in Java, a separated deployment script simplifies things.

I see no reasons which prevent you from using dtfx.js for plain java deployment but i would prefer a merged document also.

Offline DzzD
« Reply #20 - Posted 2009-03-04 11:59:19 »

Yes, a 800x600 applet takes 1333 hours to load, never noticed?
lol

detecting java is really something awefulll...

Offline h3ckboy

JGO Coder


Medals: 5



« Reply #21 - Posted 2009-03-04 12:40:56 »

for the record I was just chucking a question out so taht the post would be on topic Smiley

and I was just clearing up my understanding of the situation.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (58 views)
2014-11-26 15:22:04

toopeicgaming1999 (52 views)
2014-11-26 15:20:36

toopeicgaming1999 (10 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (27 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (76 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!