Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
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)

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda