Dmitry Makovetskiyd
Dmitry Makovetskiyd

Reputation: 7053

How to check if referrer is specified

I have been stuck on this for over one hour:

   if((document.referrer===undefined)){

  if(url_window_location=='http://www.lhttp://livecas.com/sandbox/andbox/'){
      event_google_analytics_referrer=document.referrer.toString(); 
         log("DOCUMENT REFERRER: cookie is set user_details: "+document.referrer);
        eraseCookie('user_details');
         setCookie('user_details',document.referrer,365); 
   }

    if(url_window_location=='hhttp://livecas.com/sandbox/e')
    {   
        eraseCookie('user_details');
        setCookie('landing_page_ref',"FBLND1",365);
        //   log("Cookie is set"); 
    }
 }

 else{

       if(url_window_location=='http://livecas.com/sandbox/'){
            eraseCookie('user_details');
         setCookie('user_details',"Direct",365); 
          log("Direct cookie is set");

          event_google_analytics_referrer="Direct";
      }
 }

If document.referrer is set/exists or whatever, i want it to execute the block in the if condition if not I want it the else condition. now it goes to the else condition no matter what

Upvotes: 1

Views: 7130

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324630

document.referrer always exists. It's just that sometimes it's blank (empty string).

Instead of if( document.referrer === undefined), just use if(!document.referrer) instead. This will run for all falsy values.

Upvotes: 10

Related Questions