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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browser Detection Error has me stumped, Plz help 2

Status
Not open for further replies.

Bentley22

Programmer
Aug 29, 2001
205
CA
Code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
var browser, version, br;
browser = navigator.appName;
version = navigator.appVersion;
br = &quot;&quot;;
if (browser.indexOf(&quot;Explorer&quot;) >= 0) !! (version.indexOf('4.0') >=0 )
{
  alert(&quot;MSIE 4.0 is present&quot;);
  br = &quot;ie4&quot;;
} 
<---Error Location --->
else if (browser.indexOf(&quot;Netscape&quot;) >= 0) && (version.indexOf('4.0') >=0 )
{
alert(&quot;You are using Netscape ver.4.x,. \n\n&quot;);
br = &quot;nn4&quot;; }
</script>
Thats my browser detection script, and for some reason its giving me a syntax error on the &quot;else if&quot; line, at the first character. I'll be damned if I can see why. Perhaps I just can' see the wood for the trees. If you can see the error, please post it, this is driving me nuts!
 
got it, !! should be || (shift and \) i got this to work:
Code:
var browser, version, br;
browser = navigator.appName;
version = navigator.appVersion;
br = &quot;&quot;;
if (browser.indexOf(&quot;Explorer&quot;) >= 0 || version.indexOf('4.0') >=0 ) {
  alert(&quot;MSIE 4.0 is present&quot;);
  br = &quot;ie4&quot;;
} 

else if (browser.indexOf(&quot;Netscape&quot;) >= 0 && version.indexOf('4.0') >=0 ) {
	alert(&quot;You are using Netscape ver.4.x,. \n\n&quot;);
	br = &quot;nn4&quot;; 
}
-Greg :-Q
 
catch
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
var browser, version, br;
browser = navigator.appName;
version = navigator.appVersion;
br = &quot;&quot;;
if ((browser.indexOf(&quot;Explorer&quot;) >= 0) && (version.indexOf('4.0') >=0 ))
{
alert(&quot;MSIE 4.0 is present&quot;);
br = &quot;ie4&quot;;
}
//<---Error Location --->
else if ((browser.indexOf(&quot;Netscape&quot;) >= 0) && (version.indexOf('4.0') >=0 ))
{
alert(&quot;You are using Netscape ver.4.x,. \n\n&quot;);
br = &quot;nn4&quot;; }
</script>
Victor
 
Doh! Exclimaton Points, what was I thinking! *Beats head several times against wall*

Thx for the help!
 
wow, thats the second time i mixed up || and && this morning..guess i'm not awake yet :) -Greg :-Q
 
Greg,
i ment u posted before me, but not that u're irritating me
;-) Victor
 
i know, we posted at the same time..i didn't see what you put i just saw the correction -Greg :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top