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

Anthony Webster awebster at venda.com
Wed Mar 26 04:28:29 CST 2003


there was something I wanted to ask about this though. obviously you can put 2 actions into an onclick like so:
 
<a href="#" onClick="doSomething();return (false);">Link 2</a>
 
but how do you do 2 things using this href="javascript... way:
 
<a href="javascript:doSomething();...
 
and add the return false in the same href?
 
thanks
 
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/20030326/d12385e9/attachment.htm>


More information about the Javascript mailing list