JBT
JBT

Reputation: 8756

What does "javascript://" mean?

Recently I came across something like this

<a href="javascript://">some link</a>

I have no clue what "javascript://" means in that code. Does it mean a protocol named "javascript"?

Any help is greatly appreciated.

Upvotes: 7

Views: 2434

Answers (2)

ddavison
ddavison

Reputation: 29092

Further looking into it, javascript:// is not a valid protocol.

Typically when you want to execute js via a link, you use javascript:doSomething();.

In this case,

  • Let javascript: mean "execute Javascript code after the :"
  • And let // mean a Javascript comment.

It seems to be a placeholder to do nothing, just as javascript:; would do.

So literally: execute // (do nothing)

Upvotes: 12

CuriousMind
CuriousMind

Reputation: 34175

it leads to nowhere as no url is specified.

There are some other approach to the same thing:

href="#" adds an extra entry to the browser history (which is annoying when e.g. back-buttoning).

href="" reloads the page

href="javascript:;" does not seem to have any problems (other than looking messy and meaningless)

Upvotes: 2

Related Questions