-5

I am working on to an IDE-like system using contenteditable div, my prof required us to have a feature in which we can open the textfile(local file) and show it to the contenteditable div, how can i do this trick? I've only used js, jquery and html5 and this must work on chrome.

What will i use to fetch the text? Is there a library that will format the text fetch to the contenteditable div? I havent tried anything yet, im overseeing if this is doable sorry guys. The web-based IDE is finish with bugs

extraRice
  • 323
  • 2
  • 17
  • 1
    search for HTML5 file API – A. Wolff Sep 26 '13 at 09:38
  • 4
    SO is not for helping you with your homework, and especially not when you have shown zero effort in attempting it yourself. The real shame here is that I only have 1 downvote to give. – Rory McCrossan Sep 26 '13 at 09:39
  • don`t you need something like this http://stackoverflow.com/questions/3582671/how-to-open-a-local-disk-file-with-javascript ? – zura Sep 26 '13 at 09:39

2 Answers2

2

Using jQuery it's super easy...

$("#my_div").load("text_file.txt");
Darren Crabb
  • 570
  • 2
  • 10
1

Here is a sample of some code I used ages ago:

if (window.XMLHttpRequest) {
    return new XMLHttpRequest(); //Not IE
    } else if(window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP"); //IE
    } else {
        alert("Your browser doesn't support the XmlHttpRequest object.");

    }
}    

var Req = getXmlHttpRequestObject();

Req.open("GET", "fileName.txt", true);

Req.onreadystatechange = function() {
    if (Req.readyState == 4) {
        var output = Req.responseText;
    }
}
Chris Morris
  • 943
  • 2
  • 17
  • 41