Reputation: 263
Background: My current working environment involves many navigation links that constantly updates, but the system admin will not allow PHP (or any dynamic server). This is frustrating.
Question: Is there a way to implement a class-like structure for HTML using JS to have a makeshift PHP method "include" in my HTML?
Example: For instance, I really appreciate how in PHP I can modularize the navigation links on the top of my website to a file called navbar.php and then include it to all my separate pages. Once a change has been made to the navbar.php, all the other pages will reflect the changes. Unfortunately, my workflow forces me to update all the webpages in a menial fashion. Is it possible to use JS?
Thanks!
Upvotes: 2
Views: 158
Reputation: 2092
You could use html object tag to include html too see http://www.w3schools.com/tags/tag_object.asp
Upvotes: 0
Reputation: 6814
Inserting HTML code into DIV can be done easily using the jQuery HTML function and the jQuery Load function. Basically, you give it a div and HTML code or an url and it will automatically, fill the div with the HTML page from the given URL.
As far as I've seen, you should be able to implement any dynamic behavior your might need using solely jQuery. There are still some limitation like persistence for example and your client must have JS activated for this to work (But let's face it, 99% of the customers does).
Upvotes: 1
Reputation: 11403
Create the navigation menu in pure HTML. Then, create a main div
for the content of the page, leaving it empty. Finally, use AJAX to retrieve the content of each page (as a separate pure-HTML file) and replace the contents of the main div
with it.
You can use the AJAX functions of the jQuery framework.
Upvotes: 0
Reputation: 2244
Use a js file that dynamically creates nav bar on page load and place it in all pages, you can also check which page it is using documnet.location
and highlight and all. One change in this file and all pages change
But this will be against graceful degradation, if JavaScript is disabled!!! your site is without any main navigation menu. You will have to find a work around. Create a basic pure html navigation bar, that contains your consistent links. Include a js file that replaces this with a better bar, like said above.
Upvotes: 7
Reputation: 476
Why yes. http://en.wikipedia.org/wiki/Server_Side_Includes Server side includes could go a long way towards helping you with this. It's probably the closest you can get.
Upvotes: 0