Could someone explain part of this function?

Discussion in 'Javascript' started by Nick, Jan 31, 2006.

  1. Nick

    Nick Guest

    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
    Nick, Jan 31, 2006
    #1
    1. Advertising

  2. Nick

    Nathan White Guest

    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 ;-)
    Nathan White, Jan 31, 2006
    #2
    1. Advertising

  3. Nick

    Nick Guest

    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.
    Nick, Feb 1, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gactimus
    Replies:
    22
    Views:
    707
    jeffc
    Dec 15, 2004
  2. Sean Berry
    Replies:
    3
    Views:
    283
    Tor Iver Wilhelmsen
    Apr 28, 2004
  3. Replies:
    5
    Views:
    276
    Bo Persson
    Jan 10, 2006
  4. Alexander Mahone

    Could someone please explain me this error?

    Alexander Mahone, May 2, 2008, in forum: C Programming
    Replies:
    5
    Views:
    264
    Igmar Palsenberg
    May 5, 2008
  5. wkevin
    Replies:
    4
    Views:
    567
    Edward A. Falk
    Nov 7, 2011
Loading...

Share This Page