Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Cookies getting refreshed because of my script
  ******Cookies.set("recently_viewed",'[1]' , 3, "/");*********
  var productIDArray =  JSON.parse(Cookies.get("recently_viewed"))
  if(productIDArray == null) productIDArray = [];
  productID =  window.location.href.split("product_view/")[1].split("/")[0]
  // alert(productID)
  if (productIDArray.length < 7){
    if (productIDArray.indexOf(productID) === -1) {
          productIDArray.unshift(productID);
          
      }
      
  }
  else{
    if (productIDArray.indexOf(productID) === -1) {
        productIDArray.pop(productID);
        productIDArray.unshift(productID);
        
      }
  }
  
  Cookies.set("recently_viewed", JSON.stringify(productIDArray), 3, "/");

So Im trying to execute this script which appends the product id from url to the cookie named recently_viewed. By default this cookie doesnt exist, so im being forced to use the first line which i enclosed in ***

But that keeps resetting the cookie value everytime i reload the page.

Is there any efficient way to do this?

Thanks in advance

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!