In case you're dealing with <a>
tag, and you want to interrupt going to the default href
you should use this
instead.
Go to default url (yahoo):
<a href="https://yahoo.com" onclick="location.href='https://google.com';">
Go to new url (google) onclick
:
<a href="https://yahoo.com" onclick="this.href='https://google.com';">
By using this
you're interrupting the current browser onclick
event and changing href
before continuing to default behaviour of <a href='...