Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Anchor tag - disable HREF - call javascript function

Posted on 2009-07-07
3
Medium Priority
?
874 Views
Last Modified: 2012-05-07
Experts,

I was pretty sure i knew how to do this, yet it doesnt seem to want to work in firefox, please can you look at the code below and see what im doing wrong...

It still links though to the HREF (on firefox).

Regards
Easynow
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
        <script>
                function fireAlert()
                {
			alert();
                }
  	</script>
 </HEAD>
 <BODY>
        <a href="yourlink.com" onclick="fireAlert();return false">test1</a>
        <a href="mylink.com" onclick="fireAlert();return false">test1</a>
        <a href="theirlink.com" onclick="fireAlert();return false">test1</a> 
 </BODY>
</HTML>

Open in new window

0
Comment
Question by:Dean OBrien
3 Comments
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 1000 total points
ID: 24792803
The statement alert() (with no arguments) fails.
Just alert something (ie alert("Hi there!")) and you will see that it works
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24793355
and it is nicer to return false from the function (points to VanHalen):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
        <script>
                function fireAlert()
                {
                        alert('Something');
                        return false
                }
        </script>
 </head>
 <body>
        <a href="yourlink.com" onclick="return fireAlert()">test1</a>
        <a href="mylink.com" onclick="return fireAlert()">test1</a>
        <a href="theirlink.com" onclick="return fireAlert()">test1</a> 
 </body>
</html>

Open in new window

0
 
LVL 12

Author Closing Comment

by:Dean OBrien
ID: 31600533
Cheers for comments
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question