Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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)

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •