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

204
Views
Last Page that User Visited is Not Saving in "document.referrer"

I am trying a user to redirect back to the blog he was reading after signup & tried multiple methods but user is getting redirected to either 2nd last blog or the same page (signup). Details below.

LINK TO SITE I NEED HELP WITH

  • http://mintymind.flywheelsites.com/

GOAL

  • A user reads 1 blog, clicks on 2nd blog & gets redirected to signup page.
  • User gives his email & signs up.
  • Signup page gets refreshed & shows back button (to go to last blog user was reading)

WHATS HAPPENING

  • For some reason, the "Last blog" from where user gets redirected to is not getting stored in javascript: history.go(-1) or window.history.back()

  • When I use -1 in history functions mentioned above, it stays on the same sign page probably because it was refreshed but when I even user -2 in those above history functions, it goes to "2nd last blog" user read.

OTHER SOLUTION I TRIED

if (!sessionStorage.alreadyClicked) {
    var referrer = document.referrer;
    console.log(referrer);
      
      
    localStorage.setItem("protectedReferrer", referrer);
    var protectedReferrerForInsertion = localStorage.getItem("protectedReferrer");
      
    console.log("Saved Variable was" + protectedReferrerForInsertion);   
}

document.querySelector("#back-button-referrer a").setAttribute("href", protectedReferrerForInsertion);

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Redirecting URLs don't get added to history or the referrer. You can't rely on those to record where to send somebody back to when that URL originally redirected.

They way to solve this issue is to use a URL parameter of the page to return to when redirecting to the signup page. In other words: /second-blog-article should redirect to /signup?back=/second-blog-article. That back parameter needs to be passed the entire way through the sign up process and then you redirect to it once sign up is complete.

about 4 years ago · Juan Pablo Isaza Report

0

Hey using session solved my problem. Here is the code.

jQuery(document).ready(function( $ ){
    if (top.location.pathname === '/signup/'){

        var sessionCheck = sessionStorage.getItem('visited');
        
        if(sessionCheck == null || 0 ){
            sessionStorage.setItem("visited", 0);
        }
    
        var visited = sessionStorage.getItem('visited');
        
          if (visited == 0) {
            var referrer = document.referrer;
        
            sessionStorage.setItem("localReferrer", referrer);
            sessionStorage.getItem('localReferrer');
    
            $("#back-button-referrer a").attr("href", sessionStorage.getItem('localReferrer'));
            sessionStorage.setItem("visited", 1);
        }
        else{
            $("#back-button-referrer a").attr("href", sessionStorage.getItem('localReferrer'));
        }
    }

});

about 4 years ago · Juan Pablo Isaza Report
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!