homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Import Static HTML5 Footer
HTML5, js, ajax, footer

 11:11 pm on Jan 12, 2014 (gmt 0)

Import Static HTML5 Footer

This only works in Firefox

var ajax = new XMLHttpRequest();
ajax.open("GET", "footer.htm", false);
document.body.innerHTML += ajax.responseText;

This works, but it make the code hard to read since the HTML is warped in JS.

<script type="text/javascript" src="footer.js"></script>



 12:34 am on Jan 13, 2014 (gmt 0)

Tangential answer: What exactly are you trying to do? In English, not in javascript. On the surface it looks like an SSI, but there wouldn't be any reason to use scripting for that.


 3:11 am on Jan 13, 2014 (gmt 0)

No SSI used, just some HTML wrapped in JS.

I have some footer content that needs changing at least monthly.

Maybe I should move on to php from static HTML?


 4:03 am on Jan 13, 2014 (gmt 0)

If the content is to be included routinely in every page, not in response to any user activity, then scripting isn't really appropriate anyway.

If you're including static html inside a document that is itself static html, that's an SSI. Sure you can do the same thing in php if you want to, but why bother?

How many different files will this happen to? If the included content only changes every month or so, and you have a high-traffic site, you may want to make cached copies of the finished file and serve those instead.

If you do make it php, you'll have to add a line in your htaccess to parse all html files for php. The alternative is to physically change all your file extensions, and then rewrite from html to php. (Or redirect globally, but that would be silly.) The mechanical details depend on how many files are involved, and what proportion of your total site is involved. There's more than one way to do it.

That was a lot of ifs. Oops.


 4:34 am on Jan 13, 2014 (gmt 0)

About a dozen pages.

I didn't think HTML5 & SSI could be mix together?


 7:18 am on Jan 13, 2014 (gmt 0)


News to me.

:: detour to investigate ::

Dammit, search engine, a document that talks about PHP 4 and Apache 1.3 cannot possibly be from the past year.

:: further detour to test site to see for myself ::

Far as I can tell, it doesn't care if the dtd says html 4, html 5 (that is, <!doctype html> only) or no dtd at all. Give or take a mysterious added line break which I'll worry about another time. The <!--#include happens regardless.


 7:56 am on Jan 13, 2014 (gmt 0)

SSI should work with anything. You may have extra config to do if you want to use SSI with XHTML served as application/xhtml+xml.

@lucy, Google cannot get dates right. It has a lot of page on my site, that have not changed for an year or more, showing dates from the last few months in the SERPS.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved