简体   繁体   English

手机网站重定向问题?

[英]Mobile Website Redirect issue?

i am trying to use this code to redirect to a mobile website, but when i go to my site on my phone, it does not redirect. 我正在尝试使用此代码重定向到移动网站,但是当我通过手机访问网站时,它不会重定向。 What is the problem? 问题是什么?

<script type="text/javascript">

if (screen.width <= 800 && document.referrer.indexOf('http://m.codtelevision.com') != 0) {
    window.location = "http://m.codtelevision.com";
}

</script>

Also, i need the code so if i am on my mobile site, and click Full site, it does not redirect back to the mobile site. 另外,我需要代码,因此,如果我在移动站点上,并单击“完整站点”,它不会重定向回该移动站点。

移动设备通常很少或没有Java脚本支持,您需要在服务器端脚本中检查用户代理,然后将用户从服务器重定向到移动版本,而不是使用javascript。

Try 尝试

window.location.href = "http://m.codtelevision.com";

I'm pretty sure the document.referrer thing solves your mobile site problem though I'd probably have used a session variable or cookie somewhere to indicate what type of site the user has chosen to view. 我很确定document.referrer可以解决您的移动网站问题,尽管我可能在某处使用了会话变量或cookie来指示用户选择查看的网站类型。

The answer to your latter question depends on what mobile browsers you are supporting and what sort of backend technologies you are using. 后一个问题的答案取决于您所支持的移动浏览器以及所使用的后端技术。 With plain html/javascript a cookie might work. 使用纯html / javascript,cookie可能有效。

You are on a linux server so you are probably using php for server-size scripting. 您在Linux服务器上,因此您可能使用php进行服务器大小的脚本编写。 This article explains how to redirect for mobile devices using PHP. 本文介绍了如何使用PHP重定向移动设备。 Should help: 应该帮助:

http://www.9lessons.info/2010/09/redirect-mobile-devices-with-php.html http://www.9lessons.info/2010/09/redirect-mobile-devices-with-php.html

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

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