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

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

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