Help me work around IE7/javascript issue...

Discussion in 'JavaScript' started by head in a pan, Mar 22, 2007.

  1. #1
    This is related to my last post but on a different track - maybe this is a better approach... Please don't be angry - I am losing the plot here!

    I'm trying to adapt an old piece of javascript to allow it to work with IE7 (which it wont... yet)

    At the start of my js there is a line of code:

    var ns = (navigator.appName.indexOf("Netscape") != -1);
    which detects if netscape & makes some sort of rule (I am new at this - bear with me)

    And in my searches for a IE7 equivalent I have found:
    ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom)?1:0;

    If this is the same sort of thing, how do I adapt it to my code?

    Any suggestions?
     
    head in a pan, Mar 22, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    For detecting IE7 you can use this:

    
    var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
    if (ie7==true)
    {
      document.write( "Is IE7" );
    }
    else
    {
      document.write( "Is NOT IE7" );
    }
    
    Code (markup):
    For detecting other browsers, take a look at this: http://parentnode.org/javascript/javascript-browser-detection-revisited/

    Example for Netscape:

    
    var ns4 = !BO["ie"] &&  (document.layers != null) &&  (window.confirm != null) && (document.createElement == null); 
    if (ns4)
    {
      document.write( "Is Netscape" );
    }
    else
    {
      document.write( "Is NOT Netscape" );
    }
    
    Code (markup):
     
    ajsa52, Mar 22, 2007 IP