Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is void(0) opening a new window?

Status
Not open for further replies.

cawthor

Programmer
May 31, 2001
89
US
Hi,

I have the following link in my page:

<a href="javascript:void(0);" onclick="MyFunction();">

Basically, I want the link to execute my javascript function and nothing else. It does this, but then it lauches a new window with 'javascript:void(0);' in the address bar. I thought adding the void(0) to the href tells it to do nothing. I have this same call on a different page and it works fine. But for some reason on this one page it is opening a new window. Any ideas?
 
Huh?
Code:
<a href="javascript:void(0);" onclick="MyFunction();">Click here</a>
<script language="javascript">
function MyFunction(){ alert("Hellooo..."); }
</script>
 


Code:
<a href="#" onclick="MyFunction(); return false;">Click here</a>

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Vongrunts code still launched a new window with javascript:void(); as the address. Adding the 'return false' suggested by Flava fixed it for me. Thanks guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top