Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!