Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The VeryTime,Stay informed and read the latest news today from The VeryTime, the definitive source.

Why Should I Use JavaScript With HTML Web Sites As An Include File

24
When using JavaScript in order to include objects on a web site.
I need to identify objects that I want to have updated on all of my web site pages.
Once these objects have been created I will extract the code from the source document and then create a JavaScript document which I can use to embed each object onto each page where I want that object to appear.
In setting up a form element, my desire is that the visitor, will select an element from a drop down menu which will then load the desired web page.
Here is the problem.
I only want to manage one file rather than having to update that same block of data on multiple pages.
True, PHP has the ability to use include statements, however when I am writing a pure HTML website and I do not want to use PHP on that site.
JavaScript makes it so that I have one file for each object that is included on my HTML pages where I can change or update each object file which updates all of the other pages where the JavaScript has been embed.
I use the "document.
write" method to output my code and then use a script to embed the code where I want a particular object to appear.
An object, can be a form, a menu, or other elements on the page that I want to be able to edit and where I want those changes to be made automatically updated across multiple pages.
This saves me coding time where I only have to change a few files.
If my logic was correct at the time of setting up my HTML pages then the task of editing and maintaining an HTML based website is greatly reduced.
Here is the code I use to embed a JavaScript is as shown below:
< script type="text/javascript" src="js/file.
js" >< /script >
When coding my web pages I setup a separate folder to hold all of my JavaScript files.
I find that it is best to have a standard directory structure when you develop a web site.
I have a separate folder for all my JavaScript, CSS, images and menu files.
Coding a website works best if you have an IDE, "Integrated Development Environment", tool that will help you build a web page.
I have two main IDE editors that I use.
CoffeeCup HTML Editor and Microsoft Expression Web.
An HTML editor makes it easier see your code and this help you to find errors associated with your coding.
What I like about Microsoft Expression Web is that when creating a CSS file I will add my ID tags, class statements and then link that CSS file to my HTML documents.
Then, when I move an absolute position element on the page the IDE updates my CSS file as well.
This makes it easier to positioning elements on the web page.
Before I started using a WYSIWYG, "What You See Is What You Get", type editor I had to use the manual way of setting an element on the page.
I would guess and then load and reload my HTML document until I was able to position the object in the desired location.
I am a hard coder.
Meaning I write most of my code in a IDE editor rather than using a GUI, "Graphical User Interface", or WYSIWYG type editor.
The only purpose I have for a GUI is for the easy of positioning objects on a web page.
Once I have built the objects on my web site I then determine which elements I want to be able to change on multiple pages where I can then create a JavaScript document using the "document.
write" method to include my objects on each HTML document after I have created the initial template for use on my web site.
Using JavaScript and a defined HTML directory structure this helps to sets up an environment where it is easier for me to manage my web page files and to reduce the time required to manage a pure HTML based website.
Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.