Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19931

Re: How to load common HTML code that include <Script>...</Script> to another HTML

Newsgroups comp.lang.javascript
Date 2013-05-24 11:53 -0700
References <335e7844-2549-469d-a0e3-069005a5c697@v14g2000yqm.googlegroups.com>
Message-ID <eeb4dc48-e009-46a0-afbf-c03c70ac0884@googlegroups.com> (permalink)
Subject Re: How to load common HTML code that include <Script>...</Script> to another HTML
From Danny <dann90038@gmail.com>

Show all headers | View raw


to steve nospam

the only more-or-less feasible solution, which I've used btw, is to use an XmlHttprequest() object, to fetch the "content html files" that you'd be dumping in your "template html" file, with all proper ID'ed block-level elements

Bear in mind they do not have to be as .html mimetype, they can be .txt or whatever else, it just have to be valid markup, and also be aware of the issues when using the innerHTML property, innerHTML is great for WRITES, no-so-great for READS, as in when reading or accessing nodes added with it.  As opposed to using DOM methods for adding elements/properties, which long-windy as they're, they're quite reliable for WRITE and READS

----------------------------------------
function fetcher(myfile, mydivID){
var xhrObject = new XmlHttpRequest(),
dest = document.getElementById(mydivID);

xhrObject.open('get', myfile, true);
xhrObject.onreadystate = function(){
									if (xhrObject.readyState=4) {
																 dest.innerHTML = xhrObject.responseText;
															 }
									}
xhrObject.send(null);
}
---------------------------------------
then call your "fetcher" function like

fetcher('header.html', 'myheader');
fetcher('footer.html', 'myfooter');

and so on

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to load common HTML code that include <Script>...</Script> to another HTML steve nospam <steve.nospamm@gmail.com> - 2013-05-23 22:26 -0700
  Re: How to load common HTML code that include <Script>...</Script> to another HTML steve nospam <steve.nospamm@gmail.com> - 2013-05-23 22:46 -0700
    Re: How to load common HTML code that include <Script>...</Script> to another HTML "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-05-24 09:41 +0200
  Re: How to load common HTML code that include <Script>...</Script> to another HTML Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-24 08:24 -0700
    Re: How to load common HTML code that include <Script>...</Script> to another HTML Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-05-25 21:17 +0100
  Re: How to load common HTML code that include <Script>...</Script> to another HTML Danny <dann90038@gmail.com> - 2013-05-24 11:53 -0700
    Re: How to load common HTML code that include <Script>...</Script> to another HTML Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-24 21:50 +0200
      Re: How to load common HTML code that include <Script>...</Script> to another HTML Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-24 22:15 +0200
  Re: How to load common HTML code that include <Script>...</Script> to another HTML JJ <duh@nah.meh> - 2013-05-25 04:16 +0700

csiph-web