Why is it bad practice to use links with the javascript: "protocol"?
Posted
by zneak
on Stack Overflow
See other posts from Stack Overflow
or by zneak
Published on 2010-03-19T18:07:36Z
Indexed on
2010/03/19
18:21 UTC
Read the original article
Hit count: 227
Hello everyone,
In the 1990s, there was a fashion to put Javascript code directly into <a>
href attributes, like this:
<a href="javascript:alert('Hello world!')">Press me!</a>
And then suddenly I stopped to see it. They were all replaced by things like:
<a href="#" onclick="alert('Hello world!')">Press me!</a>
For a link whose sole purpose is to trigger Javascript code, and has no real href
target, why is it encouraged to use the onclick
property instead of the href
property?
© Stack Overflow or respective owner