@@ -12,12 +12,12 @@ Practice Problems
1212
1313 <script type =" text/javascript" >
1414
15- /*
15+
1616 function getCookie (cname ) {
1717 let name = cname + " =" ;
1818 let decodedCookie = decodeURIComponent (document .cookie );
1919 let ca = decodedCookie .split (' ;' );
20- for(let i = 0; i <ca.length; i++) {
20+ for (let i = 0 ; i < ca .length ; i++ ) {
2121 let c = ca[i];
2222 while (c .charAt (0 ) == ' ' ) {
2323 c = c .substring (1 );
@@ -29,19 +29,31 @@ Practice Problems
2929 return " " ;
3030 }
3131
32- function setCookie(cname, cvalue) {
33- document.cookie = cname + "=" + cvalue + ";";
32+ /* function setCookie(cname, cvalue) {
33+ document.cookie = cname + "=" + cvalue + ";path=/;SameSite=Lax ";
3434 }*/
35+ function setCookieBothPaths (cname , cvalue ) {
36+ document .cookie = cname + " =" + cvalue + " ;path=/;SameSite=Lax" ;
37+ var here = location .pathname .substring (0 , location .pathname .lastIndexOf (' /' ) + 1 );
38+ document .cookie = cname + " =" + cvalue + " ;path=" + here + " ;SameSite=Lax" ;
39+ }
40+
41+ function deleteCookieBothPaths (cname ) {
42+ var past = " Thu, 01 Jan 1970 00:00:00 GMT" ;
43+ document .cookie = cname + " =; expires=" + past + " ;path=/" ;
44+ var here = location .pathname .substring (0 , location .pathname .lastIndexOf (' /' ) + 1 );
45+ document .cookie = cname + " =; expires=" + past + " ;path=" + here;
46+ }
3547
3648 window .onload = function () {
3749
3850 // a = document.getElementById("hparsons_lg_sql_practice")
3951 var href = ' ' ;
4052 // get prev set cookie
41- // var EXP_COOKIE = 'hparsons_lg_sql_221115'
42- // var cond = getCookie(EXP_COOKIE);
53+ var EXP_COOKIE = ' hparsons_lg_sql_221115'
54+ var cond = getCookie (EXP_COOKIE );
4355 // not using cookie here; random assignment
44- var cond = ' ' ;
56+ // var cond = '';
4557 // if no prev set cookie: generate random condition and set cookie
4658 if (cond != ' wr' && cond != ' hp' ) {
4759 var v = Math .floor (Math .random () * 2 );
@@ -50,15 +62,15 @@ Practice Problems
5062 } else {
5163 cond = ' hp' ;
5264 }
53- // setCookie (EXP_COOKIE, cond);
65+ setCookieBothPaths (EXP_COOKIE , cond);
5466 }
5567
5668 if (cond == ' wr' ) {
5769 href = " topic-3-13-experiment-practice-W.html"
5870 } else if (cond == ' hp' ) {
5971 href = " topic-3-13-experiment-practice-P.html"
6072 }
61- window .location .href = href ;
73+ window .location .replace ( href) ;
6274 };
6375 </script >
6476
0 commit comments