homepage Welcome to WebmasterWorld Guest from 54.161.191.154
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
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
EastTexas



 
Msg#: 4636965 posted 11:11 pm on Jan 12, 2014 (gmt 0)

Import Static HTML5 Footer

This only works in Firefox

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


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>

 

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4636965 posted 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.

EastTexas



 
Msg#: 4636965 posted 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?

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4636965 posted 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.

EastTexas



 
Msg#: 4636965 posted 4:34 am on Jan 13, 2014 (gmt 0)

About a dozen pages.

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

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4636965 posted 7:18 am on Jan 13, 2014 (gmt 0)

wtf?

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.

graeme_p

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 4636965 posted 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