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

118
Vistas
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 Respuestas
Responde la pregunta

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 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