简体   繁体   English

查看完整网站中的移动网站链接

[英]View mobile site link in full site

While I have a successful method of getting users from our mobile site to our full site, I need help getting them from the full site back to the mobile site. 虽然我有一种成功的方法将用户从我们的移动网站迁移到我们的整个网站,但我需要帮助将他们从整个网站迁移到移动网站。

I'm trying to use a combination of CSS and Javscript-written HTML (below) which is using server side detection. 我正在尝试结合使用CSS和使用服务器端检测的Javscript编写的HTML(如下)。 Basically the detection determines if the user is on a smart phone and, if so, writes the banner HTML. 基本上,检测将确定用户是否在智能手机上,如果是,则编写横幅HTML。 It should look like this , but unfortunately this isn't working. 它应该看起来像这样 ,但是不幸的是这没有用。 PHP isn't an option. PHP不是一个选择。

My question is, how can I get the "View Mobile" banner to appear only on smart phones (ie iPhone & Android)? 我的问题是,如何使“ View Mobile”横幅仅出现在智能手机(即iPhone和Android)上?

Here's my page and code: 这是我的页面和代码:

<meta name="viewport" content="width=device-width, user-scalable=yes" /> 
<link rel="stylesheet" type="text/css" href="css/mobile.css" media="only screen and (max-width: 640px)" />

... ...

<body> 
<script type="text/javascript">
<!--
function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
device_class = readCookie('COOKIE_DEVICE_CLASS');
if (device_class == 'smart') {
document.write('<div id="view-mobile"><a href="http://m.stanford.edu/">View Stanford Mobile</a></div>');
}
// -->
</script>

Your cookie is not being set. 您的Cookie未设置。 I visited both stanford.edu and m.stanford.edu, and I do not get a COOKIE_DEVICE_CLASS cookie. 我同时访问了stanford.edu和m.stanford.edu,但没有得到COOKIE_DEVICE_CLASS cookie。 If the cookie is created and contains 'smart' your code will work. 如果创建了cookie并包含“智能”,则您的代码将起作用。

This might work: 这可能有效:

var userAgent= navigator.userAgent.toLowerCase();

if (!!/iphone/.test(userAgent) || !!/android/.test(userAgent)) {
    // write banner
}

Create htaccess on your mobile site then add this code. 在您的移动网站上创建htaccess,然后添加此代码。

RewriteCond %{HTTP_COOKIE} !FULLSITE=yes
### Your current conditions...
RewriteRule (.*) http://your URL_mobile_add? [R,L]

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

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