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

123
Visualizações
How to run specific code javascript DOM in page at site

I want help please :(

I have several dom codes, in a js file, running on a site site.com/script.js

I want to customize a specific code, to work only on a sub-page in the site.

for example:

the codes work on site.com and I want a specific code that works

only on the site.com/page16

and code javascript just run by one file I dont have any access to html page

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can access the end part of your url by using window.location.pathname.
For the website site.com/page16 - window.location.pathname returns the string "/page16".

Next you could have a function that checks to see what the current pathname is and terminates early if the pathname doesn't match /page16.

For example:

const subPageFn = () => {
  // terminates early if subpage doesn't match page16
  if (window.location.pathname !== '/page16') {
    return
  }

  // runs page16 specific code here...
}

Then you'd call the function in any page by using

subPageFn()
about 4 years ago · Juan Pablo Isaza 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