简体   繁体   中英

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.

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.

You are on a linux server so you are probably using php for server-size scripting. This article explains how to redirect for mobile devices using PHP. Should help:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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