Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
How to capture the referring URL in a variable and then redirect to new page jquery or javascript

Almost have it, but might need a hand :

I created a script to redirect AND set a cookie that comes in from ANY page from our site. So even if a user comes in from a direct link to a news article, it will redirect them to our "splash" page and set a "cookie" to avoid further redirects. I have that part working perfect.

$(document).ready(function() {
  if (typeof Cookies.get('secondvisit') === 'undefined') {
    window.location.href = "/index-donate.php";
  }
})

However, we now want to capture the URL that they came to first and create a variable so we can have them be linked back to that page after they read our SPLASH page.

So in the example above:

Come in via direct link: /news/article1.php No cookie is detected, so we first need to "capture" the page they came in on "$page-refer" and then redirect them to our Splash page.

On the splash page, we would then present a LINK to them with "Proceed to webpage" with the "$page-refer" link.

I did try this ( BELOW ), but this is only grabbing the "google" page and not OUR webpage that they hit first.

Thanks!

$(document).ready(function() {
  if (typeof Cookies.get('secondvisit') === 'undefined') {
    var referringURL = document.referrer;
    var local = referringURL.substring(referringURL.indexOf("?"), referringURL.length);
    location.href = "/index-donate.php" + local;
  }
})
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Put together an answer that works great, thanks for the comments and push:

On footer script template:

$(document).ready(function () {
         if (typeof Cookies.get('secondvisit') === 'undefined') {
             location.href = "/index-donate.php?page-refer=" + encodeURIComponent(location.href);         
      }
   })

Then on my Splash page:

I captured the variable $pageredirect via $_GET['page-refer'] and then presented that as a link further down the page ( if set )!

about 4 years ago · Juan Pablo Isaza Denunciar

0

I think you could add the URL as a cookie when you do the redirect, ex:

$(document).ready(function () {
  if (typeof Cookies.get('secondvisit') === 'undefined') {
    Cookies.set('initialvisitedpage', window.location.href);
    window.location.href = "/index-donate.php";
  }
});

then you could redirect them to the cookie value:

$(document).ready(function() {
  if (typeof Cookies.get('secondvisit') === 'undefined') {
    window.location.href = Cookies.get('initialvisitedpage') || '/'; // or whatever this could default to in case they don't have the cookie
  }
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda