Verification of Browser Versions

Asked

Viewed 80 times

3

I am making a website and would like to put a browser check that the user is using.

I don’t want the site to be used in IE 6, 7 and 8. In addition to some versions of old Firefox that you have in those Linux environments.

If the user’s browser are some of these old ones I want to redirect the user to a page where he can download a newer browser.

But I’m wondering if these old browsers understand jQuery, why were you thinking of doing a routine through this library.

Or is there some other way to do it ? I don’t know.

  • You can use both JavaScript, how much CSS to verify the user’s browser, you can also use a language that is running on back-end, like the PHP for example.... in your case I advise using JavaScript, for this it will also be necessary to have a certain knowledge in RegEx

1 answer

4


Use the http://modernizr.com

Add this to the header:

<script src="/js/vendor/modernizr.min.js"></script>

And at the bottom of the page this:

<script>
// Detecta se o navegador é antigo
if(Modernizr.mq('only all') === false) {
   // Navegadores modernos suportam "Media Query", se o navegador não tiver suporte então direciona com location
   window.location.href = "http://exemplo/upgrade";
}
</script>
</body>
</html>

The address http://exemplo/upgrade is where you’ll get links to new browsers.

  • 1

    I use this modernizr on my sites. Apparently I don’t know how to use it right! uahuhauah Guilherme, that’s all ?

  • 1

    Yes @Diegosouza this method checks media-query support, which nowadays has in all modern browsers, if it has no support is equal to false then we use window.location :)

  • Got it, Man. Thanks, I’ll implement it and I’ll be right back!

  • It worked. I tested on IE 5, 6 and 7. Redirected to a page I’m creating now for the user to update the browser.

  • There’s a detail. I have a preloader on a specific website here. There is a way this routine can run even before this preloader loaded in window.load with jQuery ?

  • @Diegosouza it runs before the preloader yes, just do not run before the $.ready, recommend you do so: if(Modernizr.mq('only all') === false) {&#xA; window.location.href = "http://exemplo/upgrade";&#xA;} else {&#xA; /*inicia o preloder*/&#xA;}

  • I understand. But ancient browsers understand jQuery ?

  • @Diegosouza I’m not understanding, you want to run the preloader after the user downloads the new version or want it to work in any browser. As far as I understand it, you want to force the user to download a modern browser first. If this is what the "preloader" should only run if Modernizr.mq('only all') is equal to true, or to support new technologies :)

  • No bro... forget what you just said. I have a preloader. I want the browser check routine to run before the preloader. Okay? That is, when the routine sees that the browser is not compatible, it does not even load the preloader. But this preloader is loaded for $.ready, that is, jQuery. The question is: do older browsers interpret jQuery? Understand $.ready ?

  • @Diegosouza what you said was the same as I said, the example I posted doesn’t even arrive on the onload and is probably fired before the $.ready.

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.