-1

I want to make my MOBILE web site the main one. So, I want to know what HTML, CSS or Javascript code is necessary to detect a desktop PC ( like detecting the "hover" capability ) so that the mobile web site would send the user to a desktop web site version.

I already read this post: "How to detect whether the user is using mobile, tablet or desktop and redirect them?"

Explaining better:
I want to use the CSS @media function to detect a desktop PC or a laptop by using the “hover” property. If one of these devices are detected then I wanted this function to make the browser  leave this mobile web page and bring another web page ( one built for desktop PC or laptop )

Here is a pseudo-code of what I want:

<style> 
@media (hover: hover) // detects desktop PC or laptop
{
    redirect to ( “https://desktop_web_site.html”);
}
…

</style>

or a Javascript code that does the same.
  • Welcome to Stack Overflow! You say that you read [the other related question](https://stackoverflow.com/questions/33779716/how-to-detect-whether-the-user-is-using-mobile-tablet-or-desktop-and-redirect-t), but you don't say what was missing or why that didn't answer your question. What part are you struggling with? (See also: [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask)) – Mark Ormesher Sep 04 '19 at 06:25
  • Use the code from [Detecting a mobile browser](https://stackoverflow.com/questions/11381673/detecting-a-mobile-browser). If mobilecheck !== true --> Redirect to desktop version – alexP Sep 04 '19 at 06:26

2 Answers2

0

You can use UserAgent, use simple JavaScript to detect it:

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
 // some code..
}

you can refer to this answer https://stackoverflow.com/a/3540295/10828054

ink
  • 284
  • 1
  • 16
0

I already built a code that does it:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>DetectDevice</title>

</head>

<body >
    <div id="info"></div>
    <script>

    function detect_device() 
    {

      if (typeof window.orientation !== 'undefined') // if not a desktop PC
            {
                var i = "device is a MOBILE";
                document.getElementById("info").innerHTML = i;  
            }
        else
            {
                window.location = 'https://en.wikipedia.org/';
            }
    }

    window.onload = detect_device();

    </script>

</body>
</html>