href="javascript:func()" vs href="#" onclick="javascript:func()"

R

Richard Cornford

Neredbojias said:
Jukka K. Korpela wrote:

Well, javascript:void is a core javascript construct, and
if the browser supports javascript... Perhaps there is no
_specific_ _html_ spec citing "javascript:void" verbatim,
but I hardly consider that a good reason to avoid it's usage.
<snip>

As the activation/execution of javascript pseudo-protocol HREFs are well
known to directly cause numerous issues (usually perceived as problems)
in IE browsers, and an alternative exists that can achieve the same
without provoking those issues, there is no need to look for any other
reason for avoiding their use.

In practice the absence of any formal specification would be expected to
result in inconsistent implementations, and that is what is seen. For
example, while most implementations will react to the javascript
expression evaluating to a non-empty string value by replacing the
current document's contents with that string (interpreted as HTML),
IceBrowser will not replace the document with such a string.

Richard.
 
J

Jim Moe

"javascript:" is not a standard protocol. Not like "http:", "ftp:",
""ldap:", "mailto:" etc. See <http://www.faqs.org/rfcs/rfc3986.html>.
It has become a common practice among browser authors to support the
non-standard "javascript:" because some organizations (Netscape,
Microsoft) had decided to advocate it.
Well, javascript:void is a core javascript construct, [...]
Not really. It is a construct in common use.
It is misapplication of one type of construct (URI) to workaround the
limitations of another (onclick=). Such is no longer the case.
 
J

Jim Higson

Jonathan said:
Well to be precise you only use JavaScript in that post to remove the
element's styling that was hiding it...not to create the link.

Yes, but I said "Or, if the link must be created on the server-side, try
something like:" and then gave the unhiding example.

Meaning, removing the hiding would be an easy way if for some reason the OP
found it much easier to make the link on the server. I can think of a few
reasons why this might be the case. For example, under MediaWiki media
paths contain md5 hashes that are only easily knowable on the server side.

I suppose you could use PHP to write a literal string value of the hash into
the javascript, but I was just trying to keep things simple.
 
A

Adrienne Boswell

Joined
May 29, 2015
Messages
1
Reaction score
0
I have to do this i know its been AGES since anyone commented on the question so i will repeat it and give a html answer thats simple effective and a little question as to why people didnt think of it in the first place.


Howdy!
I was wondering which is better to use:

href="javascript:func()"

OR

href="#" onclick="javascript:func()"

Problem is the second one, anchors to the top of the page which is very
messy in most cases.

Thanks
Ciaran ;c)

Okay so this person is asking which is better to create a link that does nothing just clicks and unlike the href="#" onclick="javascript:func()" Well everyone was trying too much look at your basic html book and think a pure html way to create a link that doesnt do anything except click and stay in the same position is this link here
<a name="anchor" href="#anchor">Look Ma Im calling the same link that i am in so i go nowhere</a>

add your javascript functions or whatever with onclick and your link does whatever you want without going to anywhere but the same page at the same spot

<a name="anchor" href="#anchor" onclick="">Non functional link goes here and thats it</a>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top