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

201
Views
Prevent navigation if the target is the current page

In many web applications built with ASP.NET templates (new and old) there is a link at the top-left which is a link to the homepage of the site.

what I typically do is add some onclick logic to disable the click if we are already on the homepage to avoid unnecessary or errant page reloads.

Basically: Don't try to navigate to an address if I am already there.

<a href="/" onclick="return this.href!==location.href" class="navbar-brand" title="My New App">My App</a>

This code will prevent the click if the target href is the same as the href of the current location.

onclick="return this.href!==location.href"

Question: Can I do this at the document, window or location level instead of on each and every link?

I use this sparingly now, but it would be nice to paint with a broader brush.

about 4 years ago · Juan Pablo Isaza
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!