I'm creating a webpage but I want it to show a message saying that you need to use another browser when the user tries to open it with Mozilla Firefox. Can someone tell me how? Thanks.
Asked
Active
Viewed 49 times
-4
-
2Google for "js detect browser". – takendarkk Dec 12 '16 at 18:47
-
Don't do that. Provide a user experience that works in every standards-conforming browser. – Bergi Dec 12 '16 at 18:47
-
1take a look at [user agents](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox)? but these can be spoofed. there is not really a way to 100% prevent a user from accessing with a specific browser. What issues are you having with FF that you want to prevent users? Most of them can be overcome with well crafted code – happymacarts Dec 12 '16 at 18:48
-
Take a look at [this answer](http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser), This allows you to check for browser types using BROWSER Specific targeting. You would then take the `boolean` variable and run a check against it. – NSTuttle Dec 12 '16 at 18:48
-
There are a lot of different techniques for "browser sniffing," none of which are foolproof. I can't imagine a scenario where Firefox would react poorly. It would be better to fix your application to work with Firefox. But if that's simply not an option, it would probably be better to just display the page anyway, and use the browser detection to display some warning text that the page may not work correctly. – TheJim01 Dec 12 '16 at 18:49
-
2What's wrong with Firefox? – Bergi Dec 12 '16 at 18:49
-
1like @ TheJim01 stated. it may be best to display your page anyway with a message saying something like __"this page best viewed in my favorite browser"__ – happymacarts Dec 12 '16 at 18:51
-
1@Bergi My page doesn't look good at all and I cannot repair all of the errors that FF throws me (more than 100) so I prefer the user to use another browser – Aldo Dec 12 '16 at 18:56
-
3I find it hard to believe that FF throws 100 errors on a page that Chrome is happy about. What kinds of errors? – Dec 12 '16 at 19:11
-
2@Aldo The odds are on the problems being with your webpage, not the browser. Others might not throw as many warnings, but they won't like it either. – Bergi Dec 12 '16 at 19:15
-
So your problem is a combination of (1) the web page doesn't look good and (2) it throws errors? – Dec 12 '16 at 19:32
-
@torazaburo Yes, exactly – Aldo Dec 12 '16 at 19:52
2 Answers
2
var isFirefox = typeof InstallTrigger !== 'undefined';
if (isFirefox) {
alert('do not use firefox');
}

Austin
- 1,291
- 10
- 19
-
1It works perfectly! Thanks, just one question, how can I then replace the original index.html file for another saying that the user should change the browser using js?? – Aldo Dec 12 '16 at 18:58
-
What would occur if `InstallTrigger` is defined at browser other than firefox? – guest271314 Dec 12 '16 at 19:00
-
If you want to display another page, I wouldn't replace the html of index.html, but would instead redirect to another html page. window.location.href = 'http://www.google.com'; for example – Austin Dec 12 '16 at 19:02
0
if(navigator.userAgent.indexOf("Firefox") != -1 )
{
alert('Firefox');
}

Yahya Hussein
- 8,767
- 15
- 58
- 114
-
Emulating/spoofing browser agents is very easy. http://www.howtogeek.com/113439/how-to-change-your-browsers-user-agent-without-installing-any-extensions/ – TheJim01 Dec 12 '16 at 18:54
-
1if the user that is surfing the website knows that much then nothing can stop him anyway :D – Yahya Hussein Dec 12 '16 at 18:55