How to detect whether the user is using mobile, tablet or desktop and redirect them?

前端 未结 3 1191
遇见更好的自我
遇见更好的自我 2021-01-29 05:33

First off I know that a responsive site is no. 1 but at the time being that unfortunately is not an option! I also have very javascript coding skills.

I need to detect w

3条回答
  •  不要未来只要你来
    2021-01-29 06:14

    You can easily do this by showing different content with loading diff. css, if not wanting to go fully responsive. I would use @media tag of CSS, like in W3School dummy example

    @media screen and (min-width: 480px) {
        body {
            background-color: lightgreen;
        }
    }
    

    Now, as for your question, with setting the max screen size one value for phones and tablets, you usually won't have problems width catching desktops/laptops. With exclusion of new iPad Pro, 99% of tablets are 10'' and less, while phones are 6'' and less

    Personally, I would not do it your way with js, as it adds complexity where it is not needed. But this Blog post might be of help as well.

提交回复
热议问题