简体   繁体   English

移动重定向,但不是来自移动网站

[英]Mobile redirect but not when coming from Mobile site

i have this script and it works fine. 我有这个脚本,它工作正常。 I have it on the Desktop page and when a user enters it they get a question to be redirected to mobile page, this works fine. 我在桌面页面上有它,当用户输入它时,他们会有一个问题被重定向到移动页面,这很好用。 But i then have on the mobile page a link back to Desktop page, but when this link is clicked and the user gets to the Desktop page they will get the quetsion again. 但是我在移动页面上有一个返回桌面页面的链接,但是当点击此链接并且用户进入桌面页面时,他们将再次获得quetsion。 So my question is. 所以我的问题是。 Is there a way to let the Desktop page know that the user have clicked the link in Mobile page and if so do not show the Question again? 有没有办法让桌面页面知道用户点击了移动页面中的链接,如果是这样,不再显示问题? Thank you. 谢谢。

The code i have now: 我现在的代码:

<script type="text/javascript">
var isMobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent) && confirm('Realy?'));
if (isMobile)
{
   location.replace("mobile_site.html");
}  
</script>

So i also have this code. 所以我也有这个代码。 Any one know how to combind my first script with this one? 有人知道如何将我的第一个脚本与此脚本组合吗? Thank you. 谢谢。

<script>
if( /Android|webOS|iPhone|iPod|BlackBerry|IEMobile/i.test(navigator.userAgent) &&
    !window.location.href.contains("#redirected") ) {
window.location = "my_mobile_page.html";
}
</script>

This should do it - only re-direct to your mobile site if the user device isMobile and if the user has not just linked from that mobile site: 这应该这样做 - 只有当用户设备是移动设备并且用户还没有从该移动网站链接时,才会isMobile到您的移动网站:

<script type="text/javascript">
  var referrer = document.referrer;
  var isMobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent) && confirm('Realy?'));
  if (isMobile && referrer != 'mobile_site.html')
    {
     location.replace("mobile_site.html");
    }  
</script>

EDIT: Revised code to remove confirmation. 编辑:修改代码以删除确认。 If the user's device is mobile, and the referrer is not the mobile site, the confirmation prompt will display. 如果用户的设备是移动设备,而引用者不是移动站点,则将显示确认提示。 If the user accepts it, the re-direction will be triggered. 如果用户接受,则会触发重定向。 If the user is returning from the mobile site, the confirmation will not be shown. 如果用户从移动站点返回,则不会显示确认。

<script type="text/javascript">
      var referrer = document.referrer;
      if (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent) && referrer != 'mobile_site.html')
        {
        var r = confirm("Really");
            if (r == true) {
                location.replace("mobile_site.html");
            }  else {
                stop;
            }
        }
    </script>

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

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