2

I have 2 sites, and want to make someone on mobile redirect to the site automatically.

I've looked at a couple websites and videos, but I can't make them work

I'd like it to redirect mobile users to the mobile site, and keep PC/Mac users on the normal site.

cyliim
  • 181
  • 1
  • 1
  • 17
  • Possible duplicate of [What is the best way to detect a mobile device in jQuery?](https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery) – Lalji Tadhani Apr 01 '19 at 05:43
  • I usually just ignore actual device the user is on and detect the viewport: – Jimmy Westberg Apr 01 '19 at 05:45
  • https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser Pls visit the link for more clarification on detecting mobile browsers – Ram Apr 01 '19 at 05:58
  • @JimmyWestberg But the viewport is not the only difference. The absence of a mouse cursor is another, so no hovering, no hand/arrow/I-beam to distinguish different UI elements etc. A good mobile site caters to these differences. – Mr Lister Apr 01 '19 at 06:16
  • @MrLister true, but I try to use UI elements that is feeling natural for both fingers, keyboards and mouse. If we are always trying to catch each different use case we build a lot of overhead development which will make it harder to maintain in the future. But I'm not saying that's all bad. Only different ways of doing it. :) – Jimmy Westberg Apr 02 '19 at 05:49

2 Answers2

3

You can use simple javascript code.

if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent) ) {
 //code to be executed on mobile
}
Seba Cherian
  • 1,612
  • 3
  • 17
Avdhut
  • 55
  • 7
0

you can check if the Screen Size is smaller than 699.

<script type="text/javascript">
    if (screen.width <= 699) {
        document.location = "mobile.html";
    }
</script>
DevMoritz
  • 24
  • 2