Saturday, March 13, 2010

Simple Browser Java Installed or enabled detection script

Hello guys,

For those interested in simple java detection script .

here is the code.


//for mozilla ,chrome ,safari java checking
<script language="JavaScript" type="text/javascript">
// <![CDATA[

var isIE = "false";

var javawsInstalled = 0;

if (navigator.mimeTypes && navigator.mimeTypes.length) {
x = navigator.mimeTypes['application/x-java-jnlp-file'];//for firefox detection
if(x==null){

x = navigator.mimeTypes['application/x-java-vm'];//for chrome /safari
}
if(x==null){
x=navigator.mimeTypes['application/x-java-applet'];//for safari only if above fail
}
if (x) {
javawsInstalled = 1;
}
} else {
isIE = "true";
}
// ]]>
</script>

//for IE java checking
<script language="VBScript" type="text/vbscript">
// <![CDATA[
on error resume next
If isIE = "true" Then
If Not(IsObject(CreateObject("JavaWebStart.IsInstalled"))) Then
javawsInstalled = 0
Else
javawsInstalled = 1
End If
End If
// ]]>
</script>

//final alert script
<script language="Javascript" type="text/javascript">
if(!javawsInstalled){
alert('Write ur customized message to download java');//ask user to install java
}
else{
if(!navigator.javaEnabled()){
alert('Write ur customized message to enable java');//ask user to enable java from browser

}
}

No comments:

Post a Comment