[Javascript] Link to Javascript functions - what is best?

Jaime Iniesta jaime at alazan.com
Tue Mar 25 03:25:35 CST 2003


Hello, I've got a question.

 

There are 2 ways to create a link to a JavaScript function. Let's say I've
got a function like this:

 

Function doSomething()

{

                        .

}

 

And I want to link to it later on the HTML, so when the user clicks on the
link, the function is executed.

 

The first way to do this is this:

                                    

<a href="javascript:doSomething()">Link 1</a>

 

It works, but I've detected that if the page is still loading, when I click
on the link, the page stops loading, and the animated GIFs also stop its
animation.

 

So the second way, and I think is the best one, is this:

 

<a href="#" onClick="doSomething()">Link 2</a>

 

That is, having a null link (a link to #) and calling the function on the
onClick event of the link. In this way, the loading of the page is not
stopped.

 

I think this is the correct way to do this, but I've heard that on some
browsers it doesn't work.

 

An example of this second way of opening windows is on this photographs
page:

 

http://www.thismustbetheplace.net/talking-heads-pictures-band.asp

 

Thanks,

 

Jaime

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030325/4ef273f2/attachment.htm>


More information about the Javascript mailing list