nicolet Posted December 27, 2008 Share Posted December 27, 2008 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 More sharing options...
jimgilbert Posted December 27, 2008 Share Posted December 27, 2008 Maybe this is too simple, but I think it would work fine with an include of a menu that contains the links. Then if you change the menu it changes on all pages.Hope this helps.. ?Jim Link to comment Share on other sites More sharing options...
jeffman Posted December 27, 2008 Share Posted December 27, 2008 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 More sharing options...
nicolet Posted December 29, 2008 Author Share Posted December 29, 2008 Thanks to Jim Gilbert and to Deirdre's Dad. Dad's solution answers my problem best.Happy new year form Zurich!François Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.