Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The real problem I was having from the beginning was that my scripts worked if I had them on the page, but I wanted them in an external style sheet, and if I had them in an external script sheet, the scripts didn't work. So I found out how to fix it, and I'll list below everything I did to make everything listed above work perfectly.</p> <p>For those of you wondering how I detected the browser, I got it from this site: <a href="http://www.quirksmode.org/js/detect.html" rel="nofollow">http://www.quirksmode.org/js/detect.html</a>. That works sooooooooo much better <b>and</b> easier detecting it using normal javascript.</p> <p>First of all, the function should be named something other than BrowserDetect; I named it BrowserDetectMethod, like suggested by Gaby.</p> <p>And second, if I am going to include the function in an external style sheet, the external style sheet needs to be called at the <b>bottom</b> of the page. Not in the head of the page like I was trying.</p> <p>Third:</p> <p>I decided the best way to browser sniff was to find the browsers I wanted to contact, not the ones I didn't. (since there are any number of browsers out there and I only wanted to contact three)</p> <p>However, using the above method, I couldn't do that because this code doesn't work:</p> <pre><code>function BrowserDetectMethod() { if (BrowserDetect.browser != "Chrome" &amp;&amp; BrowserDetect.browser &amp;&amp; "Safari" ||BrowserDetect.browser &amp;&amp; "Firefox" ) { document.write("You're not using a supported browser"); } else { document.write("You're using a supported browser"); } } </code></pre> <p>The reason that code doesn't work is because it can't contain more than one "and" logical operator in the if statement.</p> <p>So I had to achieve the desired affect by nesting if statements like so:</p> <pre><code>function BrowserDetectMethod() { if (BrowserDetect.browser != "Chrome") { if(BrowserDetect.browser != "Firefox") { if(BrowserDetect.browser != "Safari") { document.write("You're not using a supported Browser"); } else { document.write("You're using a supported Browser"); } } else { document.write("You are using a supported Browser"); } } else { document.write("You are using a supported Browser"); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload