So... I've been asked by a friend of my brother to make a website. I've got the basic functionality up-and-running, but he also wants the text on the website to change when certain links are clicked. Solved it through an onClick function call, but in order to make it a bit more manageable, I'd like the text inserted to be stored in an external file. While this could be solved by external scripting files, it'd also require the person maintaining the site to actually not make mistakes in them (which, quite frankly, I'm fairly certain will happen). What I'd like to do is to have the actual HTML code stored in an external file, and then have the JavaScript insert that text instead (so kinda like frames, but not really). Is this doable?
0
Comments
If you want frame functionality, why not use an iframe? You can load the relevant page into there.
You have received a new honour! Congratulations! On this day, you have shown your willingness to ensure a bug-free Lusternia for everyone to enjoy. The face of Iosai the Anomaly unfolds before you, and within you grows the knowledge that you have earned the elusive and rare honour of membership in Her Order.
Curio Exchange - A website to help with the trading of curio pieces in Lusternia.
main.html contains the basic framework of the page. A header, a footer, some links, etc.
part1.html and part2.html contains a chunk of html without the head and html tags.
scripts.js contains scripts to alter main.html using innerHtml. I've got that part working fine, but the code will be maintained by someone who doesn't know html and can basically only copy-and-paste, and I don't want to introduce scripting and string concatenations (even if it's only 'test'+'test') on him.
<script>
$(function() { // This is jQuery's equivalent of document.ready
$("#link1").click(function() { //This is jQuery's equivalent of onClick bound to an element with ID 'link1'
$("#div1").load("/contents1.html"); // This is where the loading from an external file happens. As you can guess, it loads the file contents1.html from the server root directory into an element with id 'div1'
});
})
</script>
EDIT: The load function also has a filter, so you can also do something like:
$("#div1").load("/extradata.html #paragraph1"); // This will load only the element with id 'paragraph1' from the file you're loading from, so you can use a single file to hold all your extra data.
Forgiveness is the fragrance that the violet sheds on the heel that has crushed it.
You have received a new honour! Congratulations! On this day, you have shown your willingness to ensure a bug-free Lusternia for everyone to enjoy. The face of Iosai the Anomaly unfolds before you, and within you grows the knowledge that you have earned the elusive and rare honour of membership in Her Order.
Curio Exchange - A website to help with the trading of curio pieces in Lusternia.
<?php echo file_get_contents('http://EXTERNAL_URL'); ?>
it should work fine. Drop that bit of code wherever it is you want the "dynamic" html and link it out. Easy peasy. Edit: Curse you forum tags.Edit: Double post