To hide a block depending on the useragent?

As for js, you can hide a block from a specific useragent?
March 23rd 20 at 19:32
2 answers
March 23rd 20 at 19:34
We get a parser for js, this, for example, defined by UA, and I write a condition that if UA, for example, Chromium, to hide the block so-and-so.
There are parsers and easier. Everything is searched for the query 'js user agent'.
No need to parse
What ua does not need to know
But for example trying a very simple design that hides and displays a message
if (user.browser.family === 'Safari') {
 alert('You\'re using the Safari browser'); 
}

not working - tremaine.Simoni commented on March 23rd 20 at 19:37
March 23rd 20 at 19:36
var ua = window.navigator.userAgent,
element = document.querySelector('.myElement');
if(ua==="userAgent") element.style.display = "none";

Find more questions by tags JavaScript