Toon posts:

[javascript] tekstbestand openen

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hoe kan ik met behulp van javascript een bestand openen om bijvoorbeeld een regel te lezen?

  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 26-08 12:42

Janoz

Moderator Devschuur®

!litemod

JS = clientside... Weten ze meer van in W&G

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


  • D2k
  • Registratie: Januari 2001
  • Laatst online: 09-01 11:25

D2k

P&W -> W&G
Welkom in P&W -> Quickstart (update 2/10/2002)
het blijft lastig :{

Doet iets met Cloud (MS/IBM)


Verwijderd

Geript van www.scottandrew.com:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// readFile
// retrieves the contents of a local file as a JS string.
// NS4 requires Java enabled.
// Works in Mozilla 0.9.5 +

function readFile(url)
{
  var req;
  if (document.all){
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if (netscape){
    if (document.getElementById){
      req = new XMLHttpRequest();
    }
    else {
      req = new NS4HttpRequest();
    }
  }
  req.open("GET",url,false);
  req.send(null);
  return req.responseText;
}

function NS4HttpRequest()
{
  this.url = "";
  this.responseText = "";
}
NS4HttpRequest.prototype.open = function(method,url)
{
  this.url = url;
  this.method = method||get;
}
NS4HttpRequest.prototype.send = function()
{
  // thank you Mr. Pemberton
  if (this.url=="") return false;
  var line,buffer;
  this.responseText = "";
  buffer = new java.io.BufferedReader(new java.io.InputStreamReader(new java.net.URL(this.url).openStream()));
  while ((line = buffer.readLine())!=null) this.responseText+=line + "\n";
  if (buffer!=null) buffer.close();
  return true;
}

IE5+, Moz & NS4+ compatible....