帮助文档引荐来源和if..else语句 [英] Help with document-referrer and if..else statement

查看:71
本文介绍了帮助文档引荐来源和if..else语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该网站希望将移动用户的使用重定向到我们的移动版本,但是该移动网站中存在一些链接,当您单击该链接时,这些链接会将用户带回到移动首页,以使他们可以看到完整的网站及其相关内容.文章.

最初的移动检测脚本每次都会运行,因此我一直在下面尝试使用它来查看它们是否来自我们的网站内

The site is looking to redirect mobile uses to our mobile version, however there are links within the mobile site that when clicked are taking the user back to the mobile homepage, when they are meant to be see the full site and the relevant article.

The initial mobile detection script runs every time so I have been trying to use this below to see if they are coming from inside our site

if ( document.referrer.search('http://oursite.com')==-1 )
    {  do nothing...}
else    
    { include 'mobiledetection.php' }



非常感谢,如果我完全错过了标记,请原谅我!

[从答案中移出]
感谢您的回答,

但是当我尝试将index.php更改为以下网站时,该网站将无法加载.



Many thanks, forgive me if I''ve missed the mark completely!

[Moved from Answer]
Thanks for your answer,

but when I try to change the index.php to the below the site won''t load.

if ( document.referrer.search('http://oursite.com')== 0 )
{
   include "index2.php";
}
else    
{ 	
   include "mobiledetection.php";
   /* plus the other code already in the index file*/
}




index2.php只是索引中的其他先前代码,因此允许加载整个网站.

doc.ref函数是JavaScript而不是php,但是如果我尝试使用外部js,则该网站也不会加载.
请再次提供帮助:)




the index2.php being just the other previous code in the index, thus allowing the full site to load.

The doc.ref function is a javascript not php but if I try to use an external js the site won''t load either.
Please help again Smile | :)

推荐答案

除了不可靠的检查外,我看不到任何错误.通常,如果我看到与-1的比较,我的开发本能便提出抗议:因为-1是只能从文档中得知的任意数字(尽管它在搜索中非常流行,但没有任何合理的理由使用-1而不是-2等),真正合乎逻辑的比较是< 0".

更严重的是,检查是不可靠的,因为您确实需要在引荐来源字符串的开头找到该子字符串,因为它也可能是您真正不会发生的URL查询参数的一部分.

因此,您宁愿
I don''t see anything wrong except unreliable check. Generally, if I see comparison with -1, my development instincts protest: as -1 is an arbitrary number only known from documentation (even though it is very popular in search, but there is no any rational reasons to use -1 not -2, etc.), the really logical comparison is rather "<0".

More seriously, the check is not reliable because you really need this sub-string to be found at the very beginning of the referrer string, because it can also be a part of URL query parameters which you really don''t wont to happen.

So, you would rather need
if ( document.referrer.search('http://oursite.com') == 0 )
    {  /* do something... */ }
//...



—SA



—SA


这篇关于帮助文档引荐来源和if..else语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆