2015-02-12 33 views
0

我有这个脚本,它工作正常。我把它放在桌面页面上,当用户输入时,他们会得到一个问题重定向到移动页面,这很好。但是我在移动页面上有一个返回到桌面页面的链接,但是当点击此链接并且用户进入桌面页面时,他们将再次获得quatsion。所以我的问题是。有没有办法让桌面页面知道用户点击了移动页面中的链接,如果是这样,不要再次显示问题? 谢谢。手机重定向,但不是从移动网站来时

的代码,我现在:

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

只需检查引荐来源不是您的移动网页 - 如果访问者通过您的移动网页来到您的桌面页面,请勿重新引导。 – sideroxylon 2015-02-12 01:21:13

+0

不要标题解决,选择一个答案。 – vol7ron 2015-02-14 18:23:35

+0

sideroxylon - 如果用户手动切换,则不起作用,然后单击链接。 – Katana314 2015-02-14 18:31:36

回答

0

这应该做到这一点 - 只有重新定向到您的移动网站,如果用户设备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> 
+0

谢谢你的回答。我会试试这个。 – 2015-02-13 09:07:08

+0

你好,这工作差不多:)。我仍然有问题:“真的吗?”当我在手机网站点击链接到桌面页面。但是,如果我点击确定,我不会重定向,这是正确的,但我也不会whant问题。 – 2015-02-13 12:36:57

+0

请参阅上面的修改。我认为这解决了你的问题。对不起,我之前忽略了那部分。 – sideroxylon 2015-02-13 13:23:58

相关问题