Display another page when viewed from mobile

前端 未结 3 804
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-25 18:07

I have two web pages: mobile.html with mobile.css and desktop.html with desktop.css.

How can I make a redirect to the mobile one (the default page is desktop.html) if sc

3条回答
  •  半阙折子戏
    2021-01-25 18:16

    You can accomplish this with PHP, using a lightweight class such as Mobile Detect. Once downloaded and added to the server in the root of your website, you can then use this code to detect if the device is a mobile and set the location to the url of your mobile site:

    isMobile()) {
        header('Location: http://mobile.example1.com/');
        exit;
    }
    ?>
    

    Other devices can be detected and further examples can be found here

提交回复
热议问题