Jump to content

Add A Bottom Line On Load


nicolet

Recommended Posts

My pages all display the same bottom line. This line is a <p> containing links. I should like to be able to change, in future, that content in all pages, from a common .js file. François

Link to comment
Share on other sites

Maybe what Jim Gilbert is saying is that a PHP include is the normal solution here. Here is what you asked for, a javascript solution. First, you need to create an empty <p> element to hold your links. Immediately after it, add a link to a javascript. When the script loads, it will fill up the paragraph with links. Here's the HTML part:

<p id="whatever"></p><script type="text/javascript" src="links.js"></script>

Here is one way the javascript can look:

var links = [];links["Disney"] = "http://www.disney.com";links["Google"] = "http://www.google.com";links["W3Schools"] = "http://www.w3schools.com";var list = document.createElement ("ul");var item;for (var i in links) {	item = document.createElement ("li");	item.innerHTML = "<a href='" + links[i] + "'>" + i + "</a>";	list.appendChild(item);}var p = document.getElementById("whatever");p.appendChild(list);

I used a list for convenience. Obviously, you can use something else, or simply add some CSS to make this list more attractive.The advantage to storing your links in an array is that they become very manageable. Instead of wading through a lot of text to find what you want, and possibly deleting necessary characters, you can simply follow the format of the array items. So if I want to add a link called "Yahoo!" and the address is "http://www.yahoo.com", I simply add this line to my array:links["Yahoo!"] = "http://www.yahoo.com";That seems pretty convenient to me.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...