0

Is it possible to redirect a user that use a specific browser to a different link, using jQuery (or JavaScript)?

I tried this but it doesn't work:

<script type="text/javascript">
    if ((navigator.userAgent.indexOf('Firefox') != -1)
    {
        document.location = "http://other/page.com/";
    }
</script>
NineCattoRules
  • 2,253
  • 6
  • 39
  • 84

3 Answers3

2

You are doing it OK, but you have syntax error - one extra left brace, remove the one before navigator:

if (navigator.userAgent.indexOf('Firefox') != -1)
    {
        document.location = "http://other/page.com/";
    }
n-dru
  • 9,285
  • 2
  • 29
  • 42
1

Use following to redirect:

if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
    window.location.href = "http://google.com";
}

Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/location

Tushar
  • 85,780
  • 21
  • 159
  • 179
1
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
    // Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)
var isFirefox = typeof InstallTrigger !== 'undefined';   // Firefox 1.0+
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
    // At least Safari 3+: "[object HTMLElementConstructor]"
var isChrome = !!window.chrome && !isOpera;              // Chrome 1+
var isIE = /*@cc_on!@*/false || !!document.documentMode;   // At least IE6
if(isIE){
    window.location.href = "http://www.google.com";
}

Check browser: How to detect Safari, Chrome, IE, Firefox and Opera browser?

Community
  • 1
  • 1
Yellen
  • 1,785
  • 16
  • 35