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

86
Vistas
How can I prevent code execution in one page

I have to websites index.html and index.php and both pages contain a javascript file script.js.

I'd like to execute some code from script.js to index.html and other to index.php.

Is it possible to do this?

JS Code

function ChangeColor()
{
   button.addEventListener("mouseover", () =>
   {
     button.classList.remove("red");
     button.classList.add("blue");
   }
  )
  button.addEventListener("mouseout", () =>
  {
    button.classList.add("blue");
    button.classList.remove("red");
  }
  )
}

function CheckErrors()
{
  //Content
}

In My previous code, I want execute function ChangeColor in both websites because I have a button, hovewer my second function I want execute it just in index.html because I have a form.

How can I do this?, maybe with window object??

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can check whether location.pathname is equal to /index.html:

function ChangeColor() {
    button.addEventListener("mouseover", () => {
        button.classList.remove("red");
        button.classList.add("blue");
    })
    button.addEventListener("mouseout", () => {
        button.classList.add("blue");
        button.classList.remove("red");
    })
}

if (location.pathname == "/index.html") {
    function CheckErrors() {
        //Content
    }
    CheckErrors();
}
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