Forum Moderators: open

Message Too Old, No Replies

cant get external file .js to work

         

jackson88

4:16 pm on Apr 4, 2006 (gmt 0)

10+ Year Member



I cant seem to use this code from an external file but works fine embedded - i use it to set an affiliate tracking cookie

<SCRIPT LANGUAGE="JavaScript">
cookie_name = "affdataCookie";
var Entered;
var expdate = new Date();
expdate.setTime(expdate.getTime() + 26*24*60*60*1000);
{
if(document.cookie = document.cookie)
{
}
else
{
YouEntered=window.location.search
document.cookie=cookie_name+"="+Entered+"; expires=" + expdate.toGMTString();
}
}

</SCRIPT>

Fotiman

6:00 pm on Apr 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you are putting it in an external file, may sure you don't include the <script></script> tags in the file.

Also, you may have a logic error... you have an "if" statement that contains an assignment operator (=) instead of a comparision (==):


if(document.cookie = document.cookie)
-------------------^

Not sure if that's what you were going for.

jackson88

12:38 am on Apr 5, 2006 (gmt 0)

10+ Year Member



yes i noticed this all - and yes i stripped the tags before filing this. also,i did some reading and found that problem may be somthing with the fact that cookies cant be set with external files.... its some browser stuff - if it could i guess you could be passing cookies on any site you wanted to - its the single domain violation thing.

Fotiman

4:11 am on Apr 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Actually, I don't think that should matter unless maybe you're including the JS file from a different domain.

However, I notice in your example above that you're using 2 different variable names, which may be the cause of your problem:

YouEntered vs. Entered.