...

View Full Version : PSeudo SSI (server side includes)



ManagedLinks
07-05-2005, 02:54 AM
Hi

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
</script

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)

martin_narg
07-05-2005, 11:05 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<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;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
if(xmlhttp) {
xmlhttp.onreadystatechange = xmlhttpChange;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
}
}

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")
}
}
}
</script>
</head>

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


Is this something like you are looking for?

Hope this helps.

m_n

ManagedLinks
07-05-2005, 11:50 AM
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

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

m_n



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum