JavaScript: browser type and version detection

To check for a specific browser type and version and display a popup, include below code in HTML page:
<script>
if (navigator.userAgent.toLowerCase().match("safari") && navigator.userAgent.toLowerCase().match("version/4")) {
window.alert("Detected Safari 4 browser!!");
}
</script>

1 comment:

  1. Browser detection is built into a number of javascript frameworks. I'd recommend using one of these instead of rewriting the wheel!

    ReplyDelete