Last updated on January 4th, 2023 at 10:25 am
Very simple tutorial using javascript to detect browser and redirect to specific webpage using javascript. Browsers detected are Internet explorer, Chrome or Mozilla Firefox
Table of Contents
Detecting Internet Explorer
The user agent string – available in navigator.userAgent – will always include the text “MSIE”. We can then check for this in a simple indexOf:
Detecting Firefox
Thankfully, Firefox places a “Firefox” in its user agent string that is reliable for detecting it:
<script type="text/javascript">
if (navigator.userAgent.indexOf('Firefox') !=-1)
{
// Using Firefo
window.location = "http://mywebsite.com/firefoxwebpage"
}</script>
Detecting Google Chrome
Similar to Firefox, The user agent string – available in navigator.userAgent – will always include the text “Chrome”. We can then check for this in a simple indexOf:
<script type="text/javascript">
if (navigator.userAgent.indexOf('Chrome') !=-1)
{
// Using Chrome
window.location = "http://mywebsite.com/chromewebpage"
}
</script>