Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2133
  • Last Modified:

alert href

i want the href value to alert when i click.
 can we simplify the above code?
 for eg can i remove the onmouseover function? can i remove few lines in the function?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
	<script>
		function locatehref(arraynum)
		{
			var arraynum;
			var whathref;
			whathref = document.links[arraynum].href;
			alert(whathref);
		}
  </script>
 </HEAD>
 <BODY>
	<a href="yourlink.com" onmouseover="locatehref(0)">test1</a>
	<a href="mylink.com" onmouseover="locatehref(1)">test1</a>
	<a href="theirlink.com" onmouseover="locatehref(2)">test1</a> 
 </BODY>
</HTML>

Open in new window

0
vidhubala
Asked:
vidhubala
2 Solutions
 
BlomholmCommented:
This should work:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
        <script>
                function locatehref(link)
                {
                        alert(link.href);
				//return false so that you want go to the link
				return false;
                }
  </script>
 </HEAD>
 <BODY>
        <a href="yourlink.com" onclick="return locatehref(this)">test1</a>
        <a href="mylink.com" onclick="return locatehref(this)">test1</a>
        <a href="theirlink.com" onclick="return locatehref(this)">test1</a> 
 </BODY>
</HTML>

Open in new window

0
 
Göran AnderssonCommented:
Well, actually you don't need a function at all...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
   <title>A document has to have a title to be valid.</title>
</head>
<body>
   <a href="yourlink.com" onclick="alert(this.href);return false;">test1</a>
   <a href="mylink.com" onclick="alert(this.href);return false;">test1</a>
   <a href="theirlink.com" onclick="alert(this.href);return false;">test1</a> 
</body>
</html>

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now