What is href = javascript :;

there is a link href = javascript in the code I'm viewing in code. When he clicks, he opens the lightbox to show some messages with a closed button. How it's done. I think it uses dojo

+7
javascript
source share
8 answers

The code:

<a href="javascript:;">..</a> 

will actually do nothing. Typically, a Nothing link does not allow javascript to be used in place of the onclick event. The onclick event fires a window, which can be from django or jquery or anywhere.

+8
source share

Edition:

I just added this link that explains to you how dojo works with the onlclik event :

  • Dojo how to make an onclick event on a div

ok, just for the sake of it, the whole answer here is a good answer, in your particular case, if you use Dojo

<a href="javascript:;" > <a href="javascript:;" > just prevent your <a> tag to jump around when clicked and, of course, has no action!

maybe you have something like this in your code:

 <a href="javascript:;" id="some" class="some_too" rel="some_too_too"> 

Dojo just save the <a> id OR class OR rel tags and execute the function

+4
source share

href="javascript:somefunction();" is just a way to specify the function of some javascript code.

You can also do: href="#" onclick="somefunction();return false;"

Nothing really dojo about that. All he does is call a function or javascript code. It just tells the element to use javascript.

or href="javascript:void(0);" onclick="somefunction();" href="javascript:void(0);" onclick="somefunction();" as already indicated.

+1
source share

It is known as javascript pseudo-protocol. It was designed to replace the contents of a document with a value calculated using JavaScript. It is better not to use it for several reasons, including:

  • If JavaScript is disabled, you have a link that goes nowhere
  • If your JavaScript returns a value, the page content will be replaced with that value

Additional reasons why you should not use it

+1
source share

All this makes a call to a Javascript function that executes some Javascript. Perhaps adding code as an example helps.

0
source share
 <a href="javascript:void(0)" onClick="callFunction();"> 

Calling the call method () onClick

it can also be used as foollows

 <a href="javascript:callFunction();"> <a href="#" onClick="callFunction();"> 

this also calls the javascript callFunction () method, but it adds # to your URL to avoid this use.

 <a href="javascript:void(0)" onClick="callFunction();"> 
0
source share

I believe this simply indicates that your link will perform some javascript function. Usually you connect this by connecting events by reference, for example. OnClick / OnMouseMove

0
source share

Presumably, this is the URL of a resource accessible via the javascript protocol, just as you can have http: or ftp:. I do not know if this is the actual standard, but most browsers understand that the URL must be passed to the JavaScript interpreter. Thus, in practice, you can use it for JavaScript code that runs by reference, for example:

 <a href="javascript:alert('Hello!')">Say hello</a> 

Of course, writing JavaScript code inside HTML tags is neither clean nor durable. But there is an opportunity.

How about href="javascript:;" ? If you pay close attention, you will understand that ";" this is a piece of JavaScript code that, well, does nothing. This is the point. This is often used for links that do not indicate anywhere. The main goal is that clicking on it invokes JavaScript code defined elsewhere (via onclick event handlers).

Last but not least, you often see things like onclick="javascript:doStuff()" . The HTML onclick attribute expects Javascript code, not a URL. In this situation, the javascript: prefix javascript: completely redundant. However, the code still works. This is by chance a shortcut in JavaScript syntax; -)

0
source share

All Articles