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

102
Views
Redirect user on page on clicking link from google results to some URL

I want to do logic: if the user clicks on my website in Google results and goes to my website then when they click one of links on website then they are redirected to some URL (e.g. https://stackoverflow.com)

I try this way:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> 
<script>

    var ref = document.referrer;
    document.write('document.referrer: ' + ref)

           $("a").click(function() { 
            
        if (ref === "https://www.google.com/" || ref === "https://www.google.pl/") {
            window.location.href = "https://stackoverflow.com";
        }
    });

</script>

But this version redirects to normal link target not to stackoverflow.com. How can I improve this?

Now this works only when my link on website has target="_blank" then it redirects to stackoverflow.com in main window and in new window redirects to website link location.

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!