JavaScript judging browser skills sharing
Sometimes in order to compile programs or CSS syntax, we need to know the browser used by netizens. At this time, it is quite convenient to use JavaScript to obtain the browser type skills, but JavaScript itself does not have a built-in function to directly judge , I don’t know if there will be in the future. Here we share a simple approach. The concept is to use navigator.userAgent to determine whether there are related keywords in the core of the browser itself. It may sound a bit abstract, just look at the examples.
This way of writing is to allow the program to determine whether it conforms to the core of FireFox. If it is FireFox, it will return FireFox, and other browsers will return null (empty value). You can also change match to search, and the program will return the location of FireFox, if it is FireFox, if you don’t find it, it’s not FireFox browser. In the same way, we can judge other browsers, but Google Chrome and Safari Still can't distinguish clearly, try to find a way.
Browser judgment
navigator.userAgent.match("MSIE") //Determine whether it is IE
navigator.userAgent.match("Opera") //Determine whether it is Opera
navigator. userAgent.match("Safari") //Determine whether it is Safari or Google Chrome
Post a Comment
0 Comments