I have a internally run html site consisting of an index.htm and several sub pages. On these sub pages I link to files on our server (e.g. word documents, excel sheets and others). My issue is that many of my sub pages link to the same file so that when I change the filename I have to edit ALL my links on ALL my sub pages. e.g. sub1.htm has a link to text1.docx and so does sub5.htm and sub12.htm, if I then change the name of the word file to text1_ver2.docx I need to edit my links on all my sub pages.
Is there a way to have all sub pages links point at a main link and only having to edit this one main link?
I hope to have a single sub page - let's call it links.htm - with a list of all my href="text1.docx"
links and then my other href's on sub pages should simply point to the correct link on my links.htm. Then I only need to edit the destionation on the links.htm...
CodePudding user response:
You could create a variable in javascript with the url you are referring to like so:
<script>
var hrefLink = "your_url.com";
// Set the href attribute with your url
document.getElementById('word_link').setAttribute('href', hrefLink);
</script>
In your html code you would simply do the following:
<a id='word_link'>Link</a>
With this way of coding you will only have to change the url at one place and it will give the same href to all elements with the id 'word_link'. Hopefully this will help you.
CodePudding user response:
Yes, use PHP or JS ! Html is not dynamic :) Have a good day
CodePudding user response:
You really don't have to go through the pain of editing and changing the file names; that can bring about complications. Simply use JavaScript.