• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Using Hyperlinks

Using JavaScript, you can manipulate hyperlinks in a page easily. For example, take a look at this script, which changes a hyperlink’s destination URL when the user clicks a button (if you’re using JavaScript, you need NS6+ to use getElementById like this):

(Listing 14-01.html on the web site)

<HTML> 
    <HEAD> 
        <TITLE> 
            Changing a link's URL 
        </TITLE> 
        <SCRIPT LANGUAGE="JavaScript"> 
            <!--
            function changeURL()
					{
					document.getElementById("link1").href = "http://www.w3c.org"
					} 
            // --> 
        </SCRIPT> 
    </HEAD> 

    <BODY> 
        <H1>Changing a link's URL</H1> 
        Want more information? <A ID="link1" HREF="http://www.microsoft.com">Click 
here.</A> 
        <FORM> 
           <INPUT TYPE="BUTTON" ONCLICK="changeURL()" VALUE="Click me to change the link's URL"> 
        </FORM> 
    </BODY> 
</HTML> 

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint