Test, welcher Browser genutzt wird

    if (document.layers)                  // Netscape Navigator V4.x
    {
       ns4 = 1;
       ie4 = 0;
       w3c = 0;
    }
    else if (document.all)                // sonst Microsoft Internet Explorer V4.x und 5.x
    {
       ns4 = 0;
       ie4 = 1;
       w3c = 0;
    }
    else if (document.documentElement)    // sonst Microsoft Internet Explorer V5+, Opera V6+, Mozilla Firefox, Apple Safari, Google Chrome
    {
       ns4 = 0;
       ie4 = 0;
       w3c = 1;
    }
  

Kürzer hingegen ist die Abfrage mit dem konditionalen Operator:

    ns4 = (document.layers)          ? 1 : 0;   // Netscape Navigator V4.x
    ie4 = (document.all)             ? 1 : 0;   // Microsoft Internet Explorer V4.x und 5.x
    w3c = (document.documentElement) ? 1 : 0;   // Microsoft Internet Explorer V5+, Opera V6+, Mozilla Firefox, Apple Safari, Google Chrome
  
Test durchführen