Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  Plugin detection via JavaScript  (Read 3335 times)
0 Members and 1 Guest are viewing this topic.
Offline markuskidd

Junior Member


Medals: 1



« Posted 2002-11-02 18:46:10 »

Below I'm pasting in some code to determine whether or not the browser has a specified version of the plugin or above.

My intended application is to use this transparently, displaying the 'real' applet in the body if the plugin meets the specified requirement and either using document.setLocation or popping up a new window to navigate users to the "Get Java" page if not.

I'm wondering if some of you would mind testing this out in whatever browsers you have handy. I'm not particularly concerned with supporting browsers more than a generation or two ago, but correct execution on most/all current browsers is important IMO.

I have dialup access, so I need to download some other browsers anyway but it will take a while. It does work on IE 6.

detection.html
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  
<HTML>
<HEAD>
<TITLE>Detect Java Plugin</TITLE>
</HEAD>

<SCRIPT LANGUAGE="JavaScript">

function checkJavaPlugin() {

      var minimumVersion = "1.4.1";
      var applet = document.applets["DetectPluginApplet"];
      if(applet == null) {
            alert("You do not have support for Java. Please download a plugin.");
      }
      var supported = applet.meetsRequirements(minimumVersion);
      if(supported) {
            document.write("Your browser supports the minimum requirement of\n" +

minimumVersion);
      }
      else document.write("Your browser does not meet the requirement of\n" +

minimumVersion + ". At this point a call to document.setLocation() would redirect you to the

\"
Get Java\" page.");
}

</SCRIPT>

<BODY onLoad="checkJavaPlugin()">
<APPLET NAME="DetectPluginApplet" CODE="DetectPlugin.class" WIDTH=0 HEIGHT=0>
</APPLET>
</BODY>
</HTML>


DetectPlugin.java
1  
2  
3  
4  
5  
6  
7  
public class DetectPlugin extends java.applet.Applet {

      public boolean meetsRequirements(String minimumVersion){
            String version = System.getProperty("java.version");
            return version.compareTo(minimumVersion) >= 0;
      }
}


Also, any tips on improving this (especially if it turns out that it is not cross-browser-compatible) are very welcome!

Offline augusto

Senior Newbie





« Reply #1 - Posted 2002-11-02 22:22:13 »

Isn't this functionality provided by the Java Plugin HTML converter?

Anyways, one thing to watch out for is that if you compile your DetectPlugin class with the 1.4 javac, it might not run on older 1.1 VM browsers. I encountered this problem before, I think the javac -target option fixes it.
Offline markuskidd

Junior Member


Medals: 1



« Reply #2 - Posted 2002-11-05 16:13:13 »

Here are my reasons for not liking the HTML converter, from what I've seen of it:

1. You have to hard-code the URL of a specific JRE binary that you require
2. The HTML converter program does not know which JREs are available (or what directory they are in) which means you have to dig around and find it yourself
3. The HTML converter *relies* on certain browsers not recognizing certain tags. This is prone to breaking your applet when, for example, Netscape starts recognizing the COMMENT tag the same way that IE does.
4. Multi-browser support (and without using this option, why Java anyway?) requires a gigantic mess of HTML that is tricky to edit later on
5. Using my method, you can check for the user's version of Java pretty transparently on any page of your website and direct them however you like -- IE you can provide your own customized instructions on what to look for on the "Get Java" page.
6. Assuming this JavaScript/Java detection works on all or most browsers that can run Java, it is much less likely to break with future versions the browsers, since the JavaScript language is going to be backwards compatible whereas non-support for certain HTML tags is inherently not backwards-compatible
7. This mechanism is a lot closer to the process for detecting and redirecting users depending on what version of Flash they have installed. The ease of doing that is something that Sun should be imitating by now  Wink

Here is what the HTML converter spit out automatically for the DetectPlugin class:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
<!--"CONVERTED_APPLET"-->
<!-- CONVERTER VERSION 1.0 -->
<SCRIPT LANGUAGE="JavaScript"><!--
    var _info = navigator.userAgent; var _ns = false;
    var _ie = (_info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0 && _info.indexOf("Windows 3.1") < 0);
//--></SCRIPT>
<COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!--
    var _ns = (navigator.appName.indexOf("Netscape") >= 0 && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0 && java.lang.System.getProperty("os.version").indexOf("3.5") < 0) || (_info.indexOf("Sun") > 0) || (_info.indexOf("Linux") > 0)));
//--></SCRIPT></COMMENT>

<SCRIPT LANGUAGE="JavaScript"><!--
    if (_ie == true) document.writeln('<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 0 HEIGHT = 0 NAME = "DetectPluginApplet"  codebase="http://java.sun.com/products/plugin/1.1.1/jinstall-111-win32.cab#Version=1,1,1,0"><NOEMBED><XMP>');
    else if (_ns == true) document.writeln('<EMBED type="application/x-java-applet;version=1.1" java_CODE = "DetectPlugin.class" NAME = "DetectPluginApplet" WIDTH = 0 HEIGHT = 0   pluginspage="http://java.sun.com/products/plugin/1.1.1/plugin-install.html"><NOEMBED><XMP>');
//--></SCRIPT>
<APPLET CODE = "DetectPlugin.class" WIDTH = 0 HEIGHT = 0 NAME = "DetectPluginApplet" ></XMP>
<PARAM NAME = CODE VALUE = "DetectPlugin.class" >
<PARAM NAME = NAME VALUE = "DetectPluginApplet" >

<PARAM NAME="type" VALUE="application/x-java-applet;version=1.1">

</APPLET>

</NOEMBED></EMBED></OBJECT>


compare this to what I want to use:
1  
<APPLET NAME="DetectPluginApplet" CODE="DetectPlugin.class" WIDTH=0 HEIGHT=0> 


At this point, I guess it expects me to look up the cab location for win32 systems, mac systems, *nix systems, etc? The thing is, I don't even want to mess with all of this crap if I can avoid it  Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline markuskidd

Junior Member


Medals: 1



« Reply #3 - Posted 2002-11-05 22:34:56 »

... getting the chilling notion that this is only of interest to myself, but FYI it does work in Opera 6.5

Edit: The information I have right now --

Works on IE6, Netscape 7, and Opera 6.5 with 1.4.1 on Win2k. Works in IE6 with Microsoft's VM in Win2k.
Offline javatypo

Junior Member





« Reply #4 - Posted 2003-01-04 15:00:27 »

You may be able to find some good plugin detection scripts on javascript.internet.com
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.

Riven (18 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (30 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (41 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!