JavaScript Dynamic Links and Menus

Many sites use JavaScript to create links to other website pages. Here is some example
code with different link types that you may want to avoid:

<HTML>
<head>
<title>Link Examples ~ Things to stay away from</title>
<script type="text/javascript">
function gotoLocationX(){
window.location.href='http://www.cnn.com';
}
function gotoLocationY(){
window.location.href='http://www.yahoo.com';
}
function gotoLocationZ(){
window.location.href='http://www.google.com';
}
</script>
</head>
<body>

Example 1:
<a href="#" onClick="javascript:window.location.href=
'http://www.cnn.com'">News on CNN</a>
<br><br>
Example 2:
<a href="#" onClick="javascript:gotoLocationY()">Yahoo Portal</a>
<br><br>
Example 3:
<form>
<input name="mybtn" value="Google Search Engine" type=button
onClick="window.location.href='http://www.google.com'">
</form>
<br><br>
</body>
</html>

When you open this code in your browser, you will see a screen similar to Figure 8-2.
This is not to say that you can never use dynamic links. You obviously can, but you
need to think about tweaking your code to help web spiders see what they need to see.
Related Posts:
  • Javascript The + Operator The binary + operator adds numeric operands or concatenates string operands: 1 + 2 // => 3"hello" + " " + "there" // => "hello there""1" + "2" // => "12" When the values of both operands are numbers, or are both str… Read More
  • JavaScript Form Validation  JavaScript Form Validation. JavaScript can be used to validate data in HTML forms <script type="text/javascript"> function validate_all()     {     var frmReg=document.manageadmin… Read More
  • Javascript search search(regexp)The search() method is the same as indexOf() except that it takes aregular expression pattern instead of a substring. It also returns -1 if thepattern isn’t found."hello world".search(/[aeiou]/); // Find the fi… Read More
  • JavaScript Refresh Page you refresh the page using document.location.reload(). You can add the true keyword to force the reloaded page to come from the server (instead of cache). Alternatively, you can use the false keyword to reload the page from … Read More
  • Javascript Making a simple MouseOver <a href="http://www.cit.cornell.edu"onMouseOver="document.logo.src='family.gif ' ; "onMouseOut ="document.logo.src='harry.gif ' ; " ><img name="logo" src="harry.gif " border=0></a> The onMouseOver and onM… Read More
  • Embedding Content for Plug-Ins Although never officially a part of any HTML specification, the <<embed>> tag is most often used to include embedded objects for Netscape and Internet Explorer. A Macromedia Flash file might be embedded as fo… Read More
  • JavaScript Dynamic Links and Menus Many sites use JavaScript to create links to other website pages. Here is some examplecode with different link types that you may want to avoid: <HTML><head><title>Link Examples ~ Things to stay away from&l… Read More
  • Javascript Objects as Arguments You may want to write functions that take many arguments, some ofwhich are optional.function drawElement( color, border, width, height,left, top, zIndex) {// Make and display an element with these variables}drawElement("red"… Read More
  • JavaScript Popups <head><script type="text/javascript">function testPopup() {window.open( "http://www.google.com/" )}</script></head><body><form><input type="button" onClick="testPopup()" value="Click"&g… Read More
  • Javascript Recursion Recursion is when a function calls itself. This is often useful in mathematics,such as fi nding the nth number in the Fibonacci series (1, 2, 3, 5,8, 13, 21…).function fi bonacci(n) {if ( n < 2 ) {return 1;} else {return … Read More
  • JavaScript String Split Function split()The split() method splits (for lack of a better word) a string up into substrings and returns them in an array. It accepts a string or regular expression argument containing the delimiter at which the string will be b… Read More
  • Javascript Math object The Math object holds a set of constants and methods enabling more complex mathematical operations than the basic arithmetic operators var root = Math.sqrt(10); Constants Provided by the Math Object Property … Read More
  • Javascript String Constructor String is the built-in object corresponding to the primitive string data type. It contains a very large number of methods for string manipulation and examination, substring extraction, and even conversion of strings to marke… Read More
  • Javascript Image Objects Properties of Image Objects Property Description align Indicates the alignment of the image, usually “left” or “right.” alt The alternative text rendering for the image as set by the alt attribu… Read More
  • JavaScript and XML To demonstrate JavaScript, XML, and the DOM in action, let’s use Internet Explorer 5.5 or better to load an XML document containing our employee directory and see if we can manipulate it. First, to load in the document w… Read More