472,353 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Could someone explain part of this function?

Hi
I have managed to Plagiarize and modify a piece of script that checks
to see if JAVA is installed on the users pc:

function javaInstalled()
{
result = false;
if (navigator.mimeTypes &&
navigator.mimeTypes["application/x-java-vm"])
{
result = navigator.mimeTypes["application/x-java-vm"].enabledPlugin;
}
else if (document.all && (navigator.appVersion.indexOf("Mac")==-1))
{
// IE Windows only -- check for ActiveX control, have to hide code
in eval from Netscape (doesn't like try)
eval ('try {var xObj = new ActiveXObject("Javaplugin");if
(xObj) result = true; xObj = null; } catch (e) {}');
}
return result;
}

if (javaInstalled())
{
//do nothing
}
else
{
newWindow = window.open('../nojava.html', 'newWin',
'width=420,height=250')
}

I have tried it on a machine that doesn't have JAVA installed and it
works exactly as i want it to. I can't however figure out what the
"eval ('try {var xObj = new ActiveXObject("Javaplugin");if
(xObj) result = true; xObj = null; } catch (e) {}');"
bit means and it's importance, i know it doesn't work if its not
present!!!
Any help would be appreciated and also if it would work with Netscape(
not sure what the comment is saying)

Thanks

Nick

Jan 31 '06 #1
2 1601
Well technically you could just use:

window.navigator.javaEnabled();

but it has some issues with older Netscape browsers (
http://segal.org/macjavabugs/enabled/ )

In terms of your question: the new ActiveXObject is an IE specific
Object that allows you to access ActiveX. I donno how reliable this is
since it is ActiveX. It seems to me with more and more browser security
issues that ActiveX could be disabled or unaccessible to your scripts.

The other concern I have with your example is the fact that eval is
used. In this case it does not seem neccessary to have that statement
wrapped in eval. It seems like a slowdown. You function code be
simplified:

function javaInstalled(){
// if we can quickly determine java is enable return quickly
if( window.navigator.javaEnabled() ) return true;
// if netscape style plugins check to see if java is enabled
if (navigator.mimeTypes &&
navigator.mimeTypes["application/x-java-vm"]) return true;
// if IE and not the Mac version need to check ActiveXObject
else if (document.all && (navigator.appVersion.indexOf("Mac")==-1)){
try {
// create a Java ActiveX Object
var xObj = new ActiveXObject("Javaplugin");
if (xObj) return true;
} catch (e) {}
}
// if we get here we haven't detected java
return false;
}

I added comments and added a condition on the top of the function. I
did this because the script overhead will be greatly reduced if you
don't have to create an ActiveX object at least logic suggest so ;-)

Jan 31 '06 #2
Hi Nathan
Thanks for the reply
window.navigator.javaEnabled(); doesn;t actually work because as far
as i can work out it detects if it's enabled bit doesnot check if its
installed... ( i tried it on a machine with no JAVA ( or Microsoft JVM)
). The modified code doesn't work either, as testd against the
original. Thanks for your input.

Feb 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Gactimus | last post by:
Can anyone explain what the lines with the '*' by them do? ----------- #ifndef _COUNTER_H #define _COUNTER_H #include <iostream> using...
3
by: MarcJessome | last post by:
Hi, I was wondering if someone could help me through learning C++. I've tried learning before, but I find I would work better if I had someone that...
5
by: Tim Eliot | last post by:
Just wondering if anyone has hit the following issue and how you might have sorted it out. I am using the command: DoCmd.TransferText...
5
by: J Allen Horner | last post by:
I'm just starting to learn C, and the tutorial I'm reading uses this code as an example: ----------- #include <stdio.h> #define MAX 10 int...
2
by: William Morgan | last post by:
Public Declare Sub ydec_set_callback Lib "yDecLib.dll" (ByVal CallbackFunc As Long) Public Declare Sub CopyMemory Lib "kernel32" Alias...
3
by: Jan Nielsen | last post by:
Hi I am working with rowfilters in dataviews. I would like to filter for empty fields (= null value in the database) I found this sentence on...
3
by: Chris H | last post by:
I have been looking through this script and came across something that I dont quite understand how it functions or is used. Basically its brackets...
2
by: blueyonder | last post by:
The statament below does exactly what I want it to do but I don't understand why? In my mind the subquery produces a result set which is a subset...
21
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } ...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.