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

114
Vistas
Event handler to run jQuery based on URL

Is there a jQuery event handler that runs a script if the page has a certain URL? Similar to $( document ).ready(function() { but only if the page has a particular URL.

I want to run a script when the page is ready but only for a page with URL '.../something/somethingelse/'.

The view has links that redirect to new URLs to change layout aspects - but it's the same view (I'm using django web framework)

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use window.location like below:-

An example:-

if(window.location.href =='http://stacksnippets.net/js'){
  console.log(window.location.hostname);
  console.log(window.location.href);
}else{
  $('#getHostNameandHref').html(window.location.hostname +'----'+window.location.href);
  console.log('other page');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="getHostNameandHref"><div>

Note:- you can check console.log(window.location); to see what available options are there which you can use.Thanks

over 4 years ago · Santiago Trujillo 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