daled1
09-26-2011, 07:35 AM
Hi, I am trying to detect a users browsers and output a different code based on browser.
I found this code online that uses the object detection method and it works. When I document.write(BrowserDetect.browser) it outputs Chrome, (which is what I am using). The code can be found here: http://www.quirksmode.org/js/detect.html
So I can't understand why the following code does not work? It ouputs the "not" in the else statement.
I believe that BrowserDetect is an object and the .browser at the end is a property of the object.
Can one not make an object a variable? or make an object a string?
oh and BTW there is a bunch of javascript that creates the browserdetect object that can be found on the site above, but I thought it would be too unwieldy to post here. Thanks.
The following script outputs:
Chrome Not Working
<script type="text/javascript">
document.write(BrowserDetect.browser);
var browser="BrowserDetect.browser";
if(browser=="Chrome")
{
document.write(" Working");
}
else
{
document.write(" Not working");
}
</script>
I found this code online that uses the object detection method and it works. When I document.write(BrowserDetect.browser) it outputs Chrome, (which is what I am using). The code can be found here: http://www.quirksmode.org/js/detect.html
So I can't understand why the following code does not work? It ouputs the "not" in the else statement.
I believe that BrowserDetect is an object and the .browser at the end is a property of the object.
Can one not make an object a variable? or make an object a string?
oh and BTW there is a bunch of javascript that creates the browserdetect object that can be found on the site above, but I thought it would be too unwieldy to post here. Thanks.
The following script outputs:
Chrome Not Working
<script type="text/javascript">
document.write(BrowserDetect.browser);
var browser="BrowserDetect.browser";
if(browser=="Chrome")
{
document.write(" Working");
}
else
{
document.write(" Not working");
}
</script>