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>



As an Amazon Associate I earn from qualifying purchases.

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

Post Scriptum

The views in this article are mine and do not reflect those of my employer.
I am preparing to cancel the subscription to the e-mail newsletter that sends my articles.
Follow me on:
X.com (Twitter)
LinkedIn
Google Scholar

Popular Recent Posts

Most Popular Articles

apt quotation..