0
votes

How do I fire an event if the visitors browser is not a browser my code supports?

Eventually, it could be great to test if the browser supports some functions, and if it doesn't the event should be fired.

So, for instance, some browsers don't support arrow functions, so it would be good to check if the function runs and if it doesn't all remaining code should not be evaluated, and an event should be fired, telling the user that he/she must visit the website with another browser.

1
Use a polyfill/transformer? babeljs.io - Alex K.

1 Answers

0
votes

There's multiple answers to this.

Number one: web developers have been able to get along with different browsers for a while now. Shims, hacks, polyfills, transpiling, not using cutting edge features, phew.

Number two: the tests you are describing have already been done by kangax/ES6 and caniuse as well as other online services. Their test coverage can only be constructed with a pretty big testing setup.

Number three: if you must offer different versions of your website or set a minimum target, then check out the headers browsers send. I think user agent contains the versions (confusingly at first) of all the browsers that the user implements. Here's an example of what my browser sent to this website: User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36

(User-Agent is the name of the header, the rest is the content) So you could assert that if it's below Chrome 41, you serve a simpler version.

Either way, there's a lot in this topic to explore. I'd say that JavaScript is the fairly good part of it, while HTML5 is the much more worrisome one.