使网站适合移动设备

发布于 2024-08-21 08:35:13 字数 114 浏览 9 评论 0原文

有没有办法做到这一点,以便当使用手机或其他小型移动设备查看网站时,该网站会自动识别正在查看该网站,并重定向到手机友好的子域镜像或自动调用一个脚本,该脚本使它对电话友好吗?

任何文章或建议将不胜感激!

Is there a way to make it so when a site is viewed with a phone or other small mobile device the site automatically recognizes that it is being viewed as such and either re-directs to a phone friendly subdomain mirror or automatically calls a script that makes it phone friendly?

Any articles or advice would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

指尖微凉心微凉 2024-08-28 08:35:13

HTTP 请求中的 user-agent 可以帮助检测浏览器。然后,当从特定浏览器查看页面时,您可以重定向到子域。

否则, media CSS也可以使用选择器来使布局适应设备的类型。有媒体类型handheld,但我不知道它的支持程度如何。

The user-agent in the HTTP request can help detect the browser. You can then redirect to the subdomain when the page is viewed from specific browsers.

Otherwise, the media CSS selector can be used as well to adapt the layout to the kind of device. There is media type handheld, but I don't know how well it is supported.

水溶 2024-08-28 08:35:13

使用多个 CSS。

<link href="/css/mobile.css" rel="stylesheet" type="text/css" media="handheld" />

Use multiple CSS.

<link href="/css/mobile.css" rel="stylesheet" type="text/css" media="handheld" />
你的呼吸 2024-08-28 08:35:13

当然,您可以使用 JavaScript 代码来检查用户运行的浏览器类型,并对此做出适当的响应。例如:

var browser = navigator.appName;

if (browser == 'Mozilla Firefox') {
 // do something
} else if (browser == 'Some Weird Browser') {
 // do something else
}

参考:http://www.w3schools.com/js/js_browser.asp

Well, certainly you can use JavaScript code to check what kind of browsers that the users run, and respond appropiately to that. For example :

var browser = navigator.appName;

if (browser == 'Mozilla Firefox') {
 // do something
} else if (browser == 'Some Weird Browser') {
 // do something else
}

Reference : http://www.w3schools.com/js/js_browser.asp

终难遇 2024-08-28 08:35:13

有多种方法可以帮助您检测移动浏览器。以下是一些示例 PHP 代码:

function isMobileBrowser() {

  if(isset($_SERVER["HTTP_X_WAP_PROFILE"])) return true;

    if(preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) return true;

    if(isset($_SERVER["HTTP_USER_AGENT"])){

      // Quick Array to kill out matches in the user agent
      // that might cause false positives

      $badmatches = array("OfficeLiveConnector","MSIE\ 8\.0","OptimizedIE8","MSN\ Optimized","Creative\ AutoUpdate","Swapper");

      foreach($badmatches as $badstring){
        if(preg_match("/".$badstring."/i",$_SERVER["HTTP_USER_AGENT"])) return false;
      }

      // Now we'll go for positive matches

      $uamatches = array("midp", "j2me", "avantg", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda",     "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto","webos");

      foreach($uamatches as $uastring){
        if(preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"])) return true;
      }

    }
    return false;
} 

来源: http://www.brainhandles.com/技术思想/检测移动浏览器

There are several methods that can help you detect mobile browsers. Here's some sample PHP code:

function isMobileBrowser() {

  if(isset($_SERVER["HTTP_X_WAP_PROFILE"])) return true;

    if(preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) return true;

    if(isset($_SERVER["HTTP_USER_AGENT"])){

      // Quick Array to kill out matches in the user agent
      // that might cause false positives

      $badmatches = array("OfficeLiveConnector","MSIE\ 8\.0","OptimizedIE8","MSN\ Optimized","Creative\ AutoUpdate","Swapper");

      foreach($badmatches as $badstring){
        if(preg_match("/".$badstring."/i",$_SERVER["HTTP_USER_AGENT"])) return false;
      }

      // Now we'll go for positive matches

      $uamatches = array("midp", "j2me", "avantg", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda",     "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto","webos");

      foreach($uamatches as $uastring){
        if(preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"])) return true;
      }

    }
    return false;
} 

Source: http://www.brainhandles.com/techno-thoughts/detecting-mobile-browsers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文