-2

I know I asked already

I want to do the following, when somebody visits my website on the phone it should say "please visit from desktop" and when it gets visited by desktop its normal. How can I make the website detect the device and so on?

i herd of user agent but I need a html/js example of how to use it

  • You would be better off using something like Bootstrap and using the general idea from [here](https://stackoverflow.com/a/29456918/11014659) *(code below)*
    This item is not shown in desktop devices.
    – TechLoom Jan 06 '23 at 23:08

1 Answers1

-1

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.

  • Thanks this helped, yes using media queries is possible, do you have an example for that too? really the whole site just needs to be blocked and its just the text, nothing more/ On desktop normal tho. Thanks anyways – q2000 official Jan 07 '23 at 00:32