|
Posted by Jukka K. Korpela on 06/18/06 06:16
Neredbojias <http://www.neredbojias.com/fliam.php?cat=alt.html> scripsit:
>> Best solution found::::
>>
>> <a href="#" onclick="func();return false">
>>
>> This is a handy way to stop the page from jumping around but still
>> run the function.
>
> FYI, another best way is:
>
> <a href="javascript:void(0)" onclick="func()">
The first "best solution" is a link to the start of the page, with a
scripted that overrides the link functionality with the invocation of a
function, when scripting is enabled. That does not sound quite logical to
me. A self-referencing link would be slightly more logical as well as much
more practical when scripting is disabled:
<a name="foo42" href="#foo42" onclick="func();return false">
Of course, if the sole purpose of the "link" is the scripted event, then the
link should be dynamically generated using the scripting language, so that
the link is there if and only if scripting is enabled. In that case, you
could use href="error.html" where error.html is a page that explains that an
unexpected error has occurred, etc.
Using href="javascript:void(0)" does not conform to any published
specification, since there is no such spec that defines javascript: URLs.
Besides, it fails even on some old browsers that do not recognize such URLs
(or pseudo-URLs), despite supporting JavaScript.
--
Jukka K. Korpela ("Yucca")
http://www.cs.tut.fi/~jkorpela/
Navigation:
[Reply to this message]
|