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

Mobile redirect but not when coming from Mobile site

本文关键字:移动 重定向 网站 移动网      更新时间:2023-10-02

我有这个脚本,它运行得很好。我在桌面页面上有它,当用户输入它时,他们会收到一个问题,并将其重定向到移动页面,这很好。但我在手机页面上有一个返回桌面页面的链接,但当这个链接被点击,用户进入桌面页面时,他们将再次获得该链接。所以我的问题是。有没有办法让桌面页面知道用户已经点击了移动页面中的链接,如果是,就不再显示问题?非常感谢。

我现在拥有的代码:

<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>

所以我也有这个代码。有人知道如何将我的第一个剧本与这个结合起来吗?非常感谢。

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

这应该做到-只有在用户设备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>

编辑:修改代码以删除确认。如果用户的设备是移动的,而推荐人不是移动网站,则会显示确认提示。如果用户接受,将触发重定向。如果用户从移动站点返回,则不会显示确认信息。

<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>