Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-05-2005, 02:54 AM   PM User | #1
ManagedLinks
New to the CF scene

 
Join Date: Jul 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ManagedLinks is an unknown quantity at this point
PSeudo SSI (server side includes)

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
Code:
<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)
ManagedLinks is offline   Reply With Quote
Old 07-05-2005, 11:05 AM   PM User | #2
martin_narg
Regular Coder

 
martin_narg's Avatar
 
Join Date: Jul 2002
Location: Chamonix, France
Posts: 600
Thanks: 1
Thanked 3 Times in 3 Posts
martin_narg is an unknown quantity at this point
Code:
<!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
__________________
"Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
-Tommy Cooper
martin_narg is offline   Reply With Quote
Old 07-05-2005, 11:50 AM   PM User | #3
ManagedLinks
New to the CF scene

 
Join Date: Jul 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
ManagedLinks is an unknown quantity at this point
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
ManagedLinks is offline   Reply With Quote
Old 07-05-2005, 12:15 PM   PM User | #4
martin_narg
Regular Coder

 
martin_narg's Avatar
 
Join Date: Jul 2002
Location: Chamonix, France
Posts: 600
Thanks: 1
Thanked 3 Times in 3 Posts
martin_narg is an unknown quantity at this point
could well be a cross-domain issue with regards to the mozilla error. will have a look and update as necessary.

m_n
__________________
"Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
-Tommy Cooper
martin_narg is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:09 AM.


Advertisement
Log in to turn off these ads.