📜 ⬆️ ⬇️

In defense of javascript: void (0);

The other day I decided to watch the news via Google . I right-click on the “other news” link and in the context menu there is no button open in a new window. I decided to look at the source code and see javascript: void (0);
For me, this was news, because everything that I had read before was definitely against such a decision.


I mean the situation when the link runs some js code and is not used for its intended purpose, which markup is better to use?
...
or
...

Void is better than href = "#" because the behavior of href = "#" when opening in a new window for users is unexpected: the user clicks on 15 links with the right mouse button and opens each one in a new tab. As a result, he has 16 tabs with the same document.

So if suddenly the standard “javascript:” cancels there were no collisions, use onclick = “return false;” with it. Pegged by Google News:
')
...

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


All Articles