Avatar of vrmetro
vrmetro
Flag for United States of America asked on

JS cookie redirect problem

Hello,

I am using the script below to only see if a cookie is present, if so, redirecting to the page.  I believe this is setting a cookie as well.  Can someone please help edit this code so it will only check to see if cookie "COOKIENAME" is present, if so redirect to the url?

Thank you
// page to go to if cookie exists
go_to = "index.php?option=com_content&view=article&id=91&Itemid=73";
 
function readCookie(FindWhere){
    var start = document.cookie.indexOf(COOKIENAME);
    if (start == -1){ 
        document.cookie = "User=yes"; expires=" + ged(num_days)";
    } else {
        window.location = go_to;
    }
}
 
readCookie("User");

Open in new window

JavaScript

Avatar of undefined
Last Comment
vrmetro

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
hielo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hielo

>>Can someone please help edit this code so it will only check to see if cookie "COOKIENAME" is presen
If the name of your cookie is actually "COOKIENAME" then change:
if( readCookie("User") )


to:
if( readCookie("COOKIENAME") )
vrmetro

ASKER
perfect, thanks.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23