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

Anthony Webster awebster at venda.com
Tue Mar 25 03:33:38 CST 2003


the 2nd way is how you would normally be calling your javascripts, but these onclicks dont work if you are within a form in IE5.0, so that's when you would use the 1st method. 
 
its on this list that I learnt that so I'm pleased you asked!
 
ant

-----Original Message-----
From: Jaime Iniesta [mailto:jaime at alazan.com]
Sent: 25 March 2003 09:26
To: javascript at LaTech.edu
Subject: [Javascript] Link to Javascript functions - what is best?



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/5b0e4b0c/attachment.htm>


More information about the Javascript mailing list