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

91
Visualizações
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 Respostas
Responde à pergunta

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