Href and onclick issue in binding

I have an anchor link with the specified href and onclick events. Onclick sets location.href for the server url and href for another link. When a link is clicked, the href event is always fired, but the onclick event is fired only once (this is for one binding only). If I debug javascript it works correctly, what does it call both href and onclick.What could be the problem?

+4
source share
3 answers

Try

<a href="whatever.html" onclick='window.location.href="http://whereverelse";return false;'>linky</a> 

just for explanation: returning false in this case prevents the default action.

Why would you do this?

+12
source

It looks like you want the link to call up a page where the code is running on the server side (like PHP), and then direct the browser to another location. This is usually done using a server-side script to send a redirect response with a second URL.

+5
source

For those who said “Why?”, I have a reason. Average clicks Perhaps you have AJAX, which can receive information from the server and then prepare them on one page, but if the average clicker wants to see this data on a new page, they are blocked.

Thus, reports would provide the same functionality to users who want this.

Like the usual average clicker, I hate tags with passion. but I found with GreaseMonkey, sometimes I can reassign javascript href to onclick and try to parse the actual url for href. I really want opening Javascript in a new tab just clone the page and then run the code.

+1
source

Source: https://habr.com/ru/post/1285903/


All Articles