For my website, I need a menu that I can change with the uploading of one file to my host, instead of going through and recoding all the menus on many pages.
The easiest way would be to use a server-side languge: PHP or ASP or JSP, all of which allow you to include multiple source files into a single web page.
You could also convert that code into a bunch of JavaScript that would build up DOM objects one at a time.
You could also use JS to read that in as a text file and then dump the contents thereof into the innerHTML of some object on the page.
Both of the JS methods require that the page doing the importing provide some code to specify how and where to put the imported code/data.
The last, not recommended, way would be to use JS code to read in the text and use document.write( ) to put it in place on the code wherever the <script> tags that do the reading are located.
Truly, a server-side solution is the best over all. Use it if you can.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
The easiest way would be to use a server-side languge: PHP or ASP or JSP, all of which allow you to include multiple source files into a single web page.
You could also convert that code into a bunch of JavaScript that would build up DOM objects one at a time.
You could also use JS to read that in as a text file and then dump the contents thereof into the innerHTML of some object on the page.
Both of the JS methods require that the page doing the importing provide some code to specify how and where to put the imported code/data.
The last, not recommended, way would be to use JS code to read in the text and use document.write( ) to put it in place on the code wherever the <script> tags that do the reading are located.
Truly, a server-side solution is the best over all. Use it if you can.
Then that does raise another question on my side. How would I be able to get that block of coding I already did into a php format?
Then that does raise another question on my side. How would I be able to get that block of coding I already did into a php format?
You don't have to.
You can just name it "whatever.php" *WITH NO CHANGES* and do
Code:
<?php
echo "before the include<hr/>";
include "whatever.php";
echo "after the include<hr/>";
?>
If the included file does not contain <?php ... ?> tags, then it is processed as HTML.
After all, you can always go back and forth between PHP and HTML in *ANY* PHP code:
Code:
<html>
<body>
<h1>This is HTML</h1><br/>
<?php
echo "<h2>This is from PHP code</h2><br/>";
?>
And this is more HTML.<br/>
<?php
echo "And more from PHP code<br/>";
?>
</body>
</html>
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.