PDA

View Full Version : [JavaScript] Browser Detection?



Stephen!
23-06-2010, 09:08 PM
How would I go about this;

I want anybody who visits my site to get a pop-up if they're not using Google Chrome.

Is the code simple?

Cheers

Trinity
23-06-2010, 09:51 PM
I suck at javascript, but this seems to work (haven't tested it in all browsers though):


if (!navigator.userAgent.indexOf("Chrome"))
{
alert("Alert text here");
}

Source
24-06-2010, 10:25 AM
If you are using a framework such as jQuery you can do statements such as:



<script type="text/javascript">

//$.browser.msie;
//$.browser.mozilla;
//$.browser.webkit;
//$.browser.opera;

if( $.browser.webkit )
{
alert( 'This is a webkit based browser. IE: Chrome, Safari' );
}

</script>


More info here: http://api.jquery.com/jQuery.browser/

Otherwise here's a slightly different version of Trinitys code that I would use:




navigator.userAgent.toLowerCase().indexOf("chrome");



and then obviously check it has found it etc :)

Want to hide these adverts? Register an account for free!