找到网站引用者的可靠方法

时间:2015-11-10 22:06:27

标签: javascript referrer

我目前正在开展一项任务,例如用户访问满足特定条件的www.site.com我应该在页面中进行一些视觉转换。但这应该只在用户第一次显示页面时发生。随后,如果用户忽略号召性用语并浏览该站点,则一切正常。

为确保对于给定的会话,只有在我使用document.referrer检查是否存在时,才会发生此转换 1.""字符串,表示用户可能直接输入www.site.com地址

  1. document.referrer.match(/www.site.com/gi); - 确保用户不再从内部页面返回主页。
  2. 这在大多数情况下有效,除非用户进入支票渠道时,网址更改为安全的https://并且当他被引回到site.com主页时,document.referrer会返回一个空字符串,这会混淆我的逻辑a用户输入URL中的地址

    有没有其他可靠的方法来解决这个问题。非常感谢任何帮助,感谢您花时间阅读我的问题

1 个答案:

答案 0 :(得分:0)

function transformation(){
 // transformation code
}

 if(document.cookie.match(/someCookieName/) && document.location.href.match(/transformationPageURL/)){
  // call the transformation
     transformation();
    // set session cookie 
   document.cookie="someCookieName=true;";
  }else{
    // not the url to perform transformation or the cookie is already set which means its the same session.

//但是如果用户再次输入相同的主页url,由于设置了cookie,转换//将不会出现。但普通用户//访问网站并再次输入主页网址的变化可能会更少       }

相关问题