The usual behavior for a javascript:
link javascript:
is that the body of the document is replaced with all the expressions the expression evaluates to, if it is not evaluated to undefined
. There is no difference between your versions, they both evaluate to undefined
, which in javascript:
has no effect.
However, this is not the preferred way to create no-op links. Your uselessly forces the browser to parse and evaluate JavaScript. If you want to create a link that does nothing, you must set its href
to "#"
and the link click
event binding function. An event object will be passed to the event handler; if you want to evaluate some code and then prevent link tracking (adding #
to the current URL), you can use event.preventDefault()
, event.stopPropagation()
or simply return false
from the event handler.
The best option for everyone is to keep a meaningful value in your href
attribute, so if you bypass JavaScript (IE, the user opens the link in a new window), there is still some normal feedback. Then you must add extra rich actions on top of existing HTML-only functionality.
source share