I want to write some functions that are cross-browser and for this I need to know the name and current version of the browser on the client through a function, what would be the best way to do it in pure Javascript?
I want to write some functions that are cross-browser and for this I need to know the name and current version of the browser on the client through a function, what would be the best way to do it in pure Javascript?
The most accurate is to parse the header
UserAgent
; which contains data such as the browser, the version and the operating system.In this response the user makes use of regular expressions to obtain the browser and the version:
Another option is to use the bowser package :
the first answer is still correct, but for Edge you have to change it
Edge
toEdg
: