Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browser sniffer

Status
Not open for further replies.

dakone

Programmer
Jun 23, 2003
28
CA
This code is in the body of an asp page. I can't seem to get an alert box to fire when using an older version of Netscape (v 4.08). Not sure if I'm going about it right or not this is the first time I've tried to build a sniffer. Can someone tell me what I'm doing wrong?
Code:
<script language = javascript>

function Is() {
// convert all characters to lowercase to simplify testing
  var agent = navigator.userAgent.toLowerCase();
  var appVer = navigator.appVersion.toLowerCase();

  // *** BROWSER VERSION ***
  is_major = parseInt(navigator.appVersion);
  is_minor = parseFloat(navigator.appVersion);

//Netscape check
  var is_nav2 = (is_nav && (is_major == 2));
  var is_nav3 = (is_nav && (is_major == 3));
  var is_nav4 = (is_nav && (is_major == 4));
  var is_nav40 = (is_nav && (is_major == 4) && (agent.indexOf('4.0 ')!=-1));
  var is_nav401 = (is_nav && (is_major == 4) && (agent.indexOf('4.01')!=-1));
  var is_nav02 = (is_nav && (is_major == 4) && (agent.indexOf('4.02')!=-1));
  var is_nav03 = (is_nav && (is_major == 4) && (agent.indexOf('4.03')!=-1));
  var is_nav04 = (is_nav && (is_major == 4) && (agent.indexOf('4.04')!=-1));
  var is_nav05 = (is_nav && (is_major == 4) && (agent.indexOf('4.05')!=-1));
  var is_nav06 = (is_nav && (is_major == 4) && (agent.indexOf('4.06')!=-1));
  var is_nav07 = (is_nav && (is_major == 4) && (agent.indexOf('4.07')!=-1));
  var is_nav08 = (is_nav && (is_major == 4) && (agent.indexOf('4.08')!=-1));
  var is_nav450 = (is_nav && (is_major == 4) && (agent.indexOf('4.50')!=-1));
  var is_nav451 = (is_nav && (is_major == 4) && (agent.indexOf('4.51')!=-1));
  var is_nav46 = (is_nav && (is_major == 4) && (agent.indexOf('4.6')!=-1));
  var is_nav461 = (is_nav && (is_major == 4) && (agent.indexOf('4.61')!=-1));
  var is_nav47 = (is_nav && (is_major == 4) && (agent.indexOf('4.7')!=-1));
  var is_nav472 = (is_nav && (is_major == 4) && (agent.indexOf('4.72')!=-1));
  var is_nav473 = (is_nav && (is_major == 4) && (agent.indexOf('4.73')!=-1));
  var is_nav474 = (is_nav && (is_major == 4) && (agent.indexOf('4.74')!=-1));
  var is_nav475 = (is_nav && (is_major == 4) && (agent.indexOf('4.75')!=-1));
  var is_nav476 = (is_nav && (is_major == 4) && (agent.indexOf('4.76')!=-1));
  var is_nav48 = (is_nav && (is_major == 4) && (agent.indexOf('4.8')!=-1));
  var is_nav6up = (is_nav && is_minor >= 6);
//IE check
  var is_ie = (agent.indexOf(&quot;msie&quot;) != -1);
//MAC check
  var is_macie = (is_mac && is_ie);  
//Mosiac check
  var is_mosiac = (agent.indexOf(&quot;mosiac&quot;) !=- 1);
}

  var is = new Is(); 

//dynamically generate HTML markup which is optimized for the current browser
  if (is_nav2) || (is_nav3) || (is_nav4) || (is_nav40) || (is_nav401) || (is_nav02) || (is_nav03) || (is_nav04) || (is_nav05) || (is_nav06) || (is_nav07) || (is_nav08) || (is_nav450) || (is_nav451) || (is_nav46) || (is_nav461) || (is_nav47) || (is_nav472) || (is_nav473) || (is_nav474) || (is_nav475) || (is_nav476) || (is_nav48) {
    alert(&quot;This site is incompatible with Netscape 4.7 and below.  Please Upgrade to Netscape 6 at [URL unfurl="true"]www.netscape.com&quot;);[/URL]
      }
  else if (is_nav6up) {
    document.write(&quot;<input type=hidden name=ScreenSize value=\&quot;&quot; + self.screen.width +&quot;\&quot;>&quot;);
    document.write(&quot;<input type=hidden name=Browser value=\&quot;ns7up\&quot;>&quot;);
  }
  else if (is_ie) {
    document.write(&quot;<input type=hidden name=ScreenSize value=\&quot;&quot; + self.screen.width +&quot;\&quot;>&quot;);
    document.write(&quot;<input type=hidden name=Browser value=\&quot;ie\&quot;>&quot;);
  }
  else if (is_macie) {
    document.write(&quot;<input type=hidden name=ScreenSize value=\&quot;&quot; + self.screen.width +&quot;\&quot;>&quot;);
    document.write(&quot;<input type=hidden name=Browser value=\&quot;macie\&quot;>&quot;);
  }
  if (is_mosiac) {
    alert(&quot;This site is incompatible with Mosaic. Please try IE at [URL unfurl="true"]www.microsoft.com/windows/ie/default.asp[/URL] or Netscape 6 at [URL unfurl="true"]www.netscape.com&quot;);[/URL]
  }
  else {
    alert(&quot;Unrecognized Browser Detected&quot;);
  }

</script>
 
&quot;Can someone tell me what I'm doing wrong?&quot;

Attempting to support NS 4.08.

Seriously, browsers are free. If people are too lazy to download a standards compliant browser, why should you double or triple your coding efforts just to make life easier for them? You're just perpetuating their laziness. If a friend of yours had a car with a faulty fuel gauge, there would only be so many times you'd venture out in the middle of the night with a can of fuel to help before telling them to get their fuel gauge fixed right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top