简体   繁体   English

Javascript移动网站重定向问题

[英]Javascript mobile site redirect issues

I'm using code to redirect mobile devices that are under 699 pixels wide to go to our mobile site. 我正在使用代码重定向宽度小于699像素的移动设备转到我们的移动网站。 This method utilizes JavaScript and cookies and follows some basic logic: 此方法利用JavaScript和cookie,并遵循一些基本逻辑:

  • Do not run logic for redirect if cookies are disabled 如果禁用了cookie,请不要运行重定向逻辑
  • Do not redirect if cookie skipmobile is set to 1 如果cookie skipmobile设置为1,请不要重定向
  • Redirect only if skipmobile is not 1, and your mobile device is listed below and under 699 pixels wide. 仅当skipmobile不为1且您的移动设备在下方和699像素宽以下列出时,才进行重定向。

     //{{Full Site Code}} Only run logic if cookies are enabled. if(navigator.cookieEnabled){ //If the cookie skipmobile is already set do not redirect to mobile. if (document.location.search.indexOf("skipmobile") >= 0) { document.cookie = "skipmobile=1"; } //If the device is one of the types listed below and is under 699 pixels wide, redirect to the mobile site. else if (((/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) && screen.width < 699) && document.cookie.indexOf("skipmobile") == -1) { document.location = "'.MOBILE_SITE.$direct.'"; } } 

On the mobile site I simply have a link like the following that someone can click to set the cookie 在移动网站上,我仅具有如下链接,有人可以单击该链接来设置cookie

http://www.example.com?skipmobile=1

This code works properly for me and most people, but we are having customers saying When they click the full site link it sends them right back to the mobile site. 该代码对我和大多数人均适用,但是我们让客户说,当他们单击完整的站点链接时,它将立即将其发送回移动站点。 According to the code this means they do have cookies enabled but their cookie isn't getting set. 根据代码,这意味着他们确实启用了cookie,但是没有设置它们的cookie。

Is there something I need to do to this code that's missing? 我需要对丢失的代码执行某些操作吗?

UPDATE: So this problem is a bit of an oddball. 更新:所以这个问题有点奇怪。 One of our employees is having the issue as well so we at least have a phone to test on. 我们的一名员工也遇到了问题,因此我们至少有一部手机可以测试。 We have a live site and a dev site. 我们有一个实时站点和一个开发站点。 It works for him of we go to the dev site and redirect but it doesn't for the live... 它对他有用,因为我们转到开发站点并重定向,但不适用于现场...

Does this help anyone come up with conclusions? 这是否有助于任何人得出结论? The code is the same on both sites. 两个站点上的代码相同。

You should try deleting all cookies related to your site beforehand, as this should clear up any problems. 您应该尝试事先删除与您的网站相关的所有cookies ,因为这样可以清除所有问题。 This is a link to a great function that should do this for you: 这是一个功能强大的链接,应为您执行此操作:

Clearing all cookies with JavaScript 使用JavaScript清除所有cookie

You could also put that you don't want it to cache for a while in the headers (using the cache control var) to make sure that if the phone is storing any problems these are removed 您还可以在标题中声明您不希望它暂时缓存(使用缓存控件var),以确保如果手机存储了任何问题,这些问题都将被删除。

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

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