views:

268

answers:

8

in a code which i am goin through there is a link has href=javascript:; in code.when it is clicked it opens a lightbox to show some msg with close button.how is it done.I think this uses dojo

A: 

All this does is make a call to a javscript function which executes some javascript. Maybe posting the code as an example helps.

Rob
@Rob: `href=javascript;` is the code....
James
bit strange, normally the code is as david stated<a href="#" onclick="somefunction();">yourlinktext</a> Is the link showing as url or image? I know lightbox uses the 'rel' attribute on images to show a fancy lightbox effect and let an image popup
Rob
@Rob, he probably has an addEventListener somewhere else in the code.
teehoo
@teehoo Do these respond to href=javascript; then?
Rob
+1  A: 

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

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

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

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

SoLoGHoST
imho `return false;` is missing in the example with `href="#"`
binaryLV
You can also do: `href="#" onclick="sommefunction();"`
David Murdoch
yeah, either will work, but yes, binaryLV is correct, it should return false, since there is no url specified. Corrected this. Cheers :) Though you can specify `javascript:void(0);` and you won't need to worry about returning false from this.
SoLoGHoST
And furthermore, it's `onclick` not `onClick` please make sure to use the correct attribute the way it is meant to be, otherwise, you'll get XHTML validation errors on your webpages.
SoLoGHoST
A: 
<a href="javascript:void(0)" onClick="callFunction();">

Call callFunction() method onClick

this can also be used as foollows

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


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

this also call javascript callFunction() method but it adds # in your URL to Avoid this Use

<a href="javascript:void(0)" onClick="callFunction();">
Salil
there are reasons why people use the onclick event...
Russell
A: 

I believe this just indicates that your link is going to perform some javascript function. Usually you couple this by hooking up events on the link e.g. OnClick/OnMouseMove

James
+5  A: 

The code:

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

will actually do nothing. Generally this Nothing link allows some javascript code to use the onclick event instead. The onclick event triggers the window which may be from django or jquery or wherever.

Russell
+1  A: 

It's known as the javascript pseudo-protocol. It was designed to replace the contents of the document with a value calculated by JavaScript. It's best 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 contents of the page will be replaced by that value

More reasons why you shouldn't use it

Tim Down
A: 

Supposedly, it's a URL to a resource that's reachable via the "javascript" protocol, just like you can have "http:" or "ftp:". I don't know if it's an actual standard but most browsers understand that the URL must be fed to the JavaScript interpreter. So, in practise, you can use it to have JavaScript code that's triggered by a link, e.g.:

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

Of course, writing your JavaScript code inside HTML tags is neither clean nor mantainable. But the possibility exists.

What about href="javascript:;"? If you pay close attention, you'll realise that ";" is a JavaScript code snippet that, well, does nothing. That's the point. This is often used to have a link that points nowhere. The main purpose is that clicking on it triggers JavaScript code defined somewhere else (via onclick event handlers).

Last but not least, you often see stuff like onclick="javascript:doStuff()". The onclick HTML attribute expects Javascript code, not a URL. In this situation, the javascript: prefix is totally superfluous. However, the code still runs. It happens to be a label in JavaScript syntax just by chance ;-)

Álvaro G. Vicario
+3  A: 

EDITED:

i have just added this link that explane you how dojo work with onlclik event:

ok, just for the sake, all the answer here are good answer, in your particular case if you are using Dojo

the <a href="javascript:;" > simply prevent your <a> tag to jump around when clicked and of course have no action!

probably you have something like this in your code:

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

Dojo simply keep the <a> id OR class OR rel tags and execute the function!

aSeptik