Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 987
JBT Avatar asked May 17 '13 15:05

JBT


2 Answers

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)

like image 146
ddavison Avatar answered Sep 27 '22 17:09

ddavison


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)

like image 21
CuriousMind Avatar answered Sep 27 '22 18:09

CuriousMind