javascript - Set a Cookie based on url Parameter -


i need set cookie whenever user clicks through 1 of our affiliate links , lands on our site "src=uni" in url. urls this:

http://www.myadmin.com?src=uni&utm_source=uni&utm_content=[publisher_id]

function create cookie:

 function setcookie() {             var url = window.location.href;             if(url.indexof('?src' + uni) = 1)                 document.cookie="querycookie";     } 

can me telling going wrong in creating cookie based on query parameters?

a few things here:

function setcookie() {     var url = window.location.search;     if(url.indexof('?src=uni') !== -1)         document.cookie="src=uni"; } 

1) use location.search narrow down range, not necessary, less room error,

2) use !== -1 test indexof method. indexof returns "-1" if not find match. , "0" if finds match @ beginning of string. string "zero indexed" means first character in string in position "0".

3) add equal sign = along parameter name: src=.

4) also, use string "uni" if you're looking for, rather variable named uni. if "src" can variety of values, we'll need add more logic account that.

5) , when assigning document.cookie use key/value pairs in: key=value.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -