View Full Version : PSeudo SSI (server side includes)

07-05-2005, 03:54 AM

I am looking for a way to include text on a page similar to SSI but I want to do it dynamically and I don't want to use iframes.

I need a way to load the text from the source url and then write it out to the current document when required

The easy part is writing it to the document, the hard part is accessing it in the first place. I tried iframes as an intermediary but found I had cross domain security problems. I could only load the text if it came from my own domain

So i was thinking if I create a script element eg

<script id="theirtext" src="someotherdomain.com/texttoinclude.txt">
// unwanted stuff

I could then read the text that was brought in and write it to the document when required

unfortunately I cannot find a way to access the actual text

I can only access the unwanted stuff with id.innerHTML or id.text

Does anyone know how I can access the file that was read in by the src="" statement?

perhaps there is another way? another element perhaps or maybe XML (I know next to nothing about xml)

07-05-2005, 12:05 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Read remote file</title>
<script type="text/javascript">
/* XML HTTP code taken from
* http://www.w3schools.com/xml/xml_http.asp
var xmlhttp;
function loadXMLDoc(url) {
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = xmlhttpChange;
else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
if(xmlhttp) {
xmlhttp.onreadystatechange = xmlhttpChange;

function xmlhttpChange() {
if(xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
// Place the contents of the file into the textarea
document.frm.txt.value = xmlhttp.responseText;
else {
alert("Problem reading file")

<body onload="loadXMLDoc('http://www.bbc.co.uk/');">
<form name="frm">
<textarea name="txt" cols="50" rows="10"></textarea>

Is this something like you are looking for?

Hope this helps.


07-05-2005, 12:50 PM
Excellent, Better than I expected :)

Unfortunately the Mozilla version doesnt work. it throws an access denied error when trying to open the url.

But it certainly is good enough for my needs.

many thanks

07-05-2005, 01:15 PM
could well be a cross-domain issue with regards to the mozilla error. will have a look and update as necessary.