Using the JavaScript User Agent would lead to solutions which are unnecessarily complicated or unreliable. Instead, simply detect mobile devices by the viewport width. If you had mentioned CSS in your question, I would strongly reccomend you to use media queries. However, here is a JavaScript solution:
if (window.innerWidth < 1024) {
alert('Please, visit from desktop!');
}
The code above considers that every device whose screen is narrower than 1024px is a mobile device. That's a common breakpoint value, however you could change it. Also, instead of using the alert
function, you could show an HTML element containing your message, for example.