Introduction
Many times in web developing, I have come across problems having to edit 10-15 web pages every time I wanted to change something about my website. So, not knowing PHP or not wanting to use SSIs, I decided to find a workaround with JavaScript. In this article, you will learn how to separate your pages into sections and quickly and easily edit them from one small JavaScript file.
Using the code
Now, to start, create a JavaScript (.js) file and name it quick_edit. Then, make a reference to the JavaScript file by adding this to the header of your page:
<script language="JavaScript 1.3" type="text/javascript" src="quick_edit.js"></script>
Then, you will have to break your website up into sections (ones that change often). For example, Header, Side Menu, and Footer. The main content of the page usually varies between pages, so any thing that changes here will have to be done by manually editing the file.
Break your page up into sections like this:
<!--
<script type="text/javascript">
<!--
HeaderInsert();
</script>
You will use one of these for each section that you want to be able to edit quickly.
Finally, just create a function in your JavaScript file and add a Document.Write
to it. Like this:
function HeaderInsert()
{
document.write('<h1 align="center">Quick Edit Test Page</h1>');
}
The content that you want to be able to change quickly is all in the Document.Write
. All content must stay on one line, no line breaks can be used (which limits the organization of your code).
Conclusion
Well, that's about it. This is a crazy work-around, but it works. I wouldn't suggest it for anything serious like a business website, but for a simple personal website, it works fine.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.