繁体   English   中英

如何使移动网页成为主要网页,并在检测到此类设备时将用户转移或重定向到桌面网页?

[英]How To Make A Mobile Web Page The MAIN One And Only Divert Or Redirect The User To The Desktop Web Page When Such Device Is Detected?

我想让我的移动网站成为主要网站。 所以,我想知道检测台式电脑需要哪些HTMLCSSJavascript代码(例如检测“悬停”功能),以便移动网站将用户发送到桌面网站版本。

我已经读过这篇文章:“如何检测用户是使用手机、平板电脑还是台式机并重定向它们?”

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.

您可以使用UserAgent ,使用简单的JavaScript来检测它:

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

你可以参考这个答案https://stackoverflow.com/a/3540295/10828054

我已经构建了一个代码:

<!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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM