• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Is it possible to write javascript to display files in textarea?

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The example at http://www.faqts.com/knowledge_base/view.phtml/aid/1899/fid/130 can display files that are in the same directory in a textarea. But it doesn't work to display files that are in other directory. Please help me to get a solution to display client-side files in a textarea. Thanks!
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can browse your local filesystem like this:

/Rene
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Based on your suggestion, here is my try, but I still got a running error message "Permission denied" at the line downloader.startDownload(fileName, displayFile. Can you thy this, and let me know what the problem is? thanks!
<html xmlns:msie>
<msie ownload id="downloader" style="behavior:url(#default#download)" />
<HEAD>
<SCRIPT>
function fetchURL(url) {
if ((location.host == '' && url.indexOf(location.protocol) == -1)
||
url.indexOf(location.host) == -1)
{
netscape.security.PrivilegeManager.enablePrivilege
("UniversalConnect");
}
var dest = new java.net.URL(url);
var dis = new java.io.DataInputStream(dest.openStream());
var res = "";
while ((line = dis.readLine()) != null) {
res += line;
res += java.lang.System.getProperty("line.separator");
}
dis.close();
return res;
}
</SCRIPT>
<SCRIPT>
function loadFile (fileName) {
fileName = "file:///" + fileName.replace(/\\/g,'/');
if (document.layers) {
var i = new Image();
i.src = fileName;
var fileURL = i.src;
document.formName.file.value = fetchURL(fileURL);
}
else if (document.all && document.getElementById){
downloader.startDownload(fileName, displayFile);
}
}
function displayFile (text) {
document.formName.file.value = text;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<SELECT NAME="files"
ONCHANGE="if (this.selectedIndex > 0)
loadFile(this.options[this.selectedIndex].value);"
>
<OPTION>-- Select a file to display --
<OPTION VALUE="C:\Temp\disclaimer.html">disclaimer.html
<OPTION VALUE="test.html">test.html
</SELECT>
<BR><BR>
<TEXTAREA NAME="file" ROWS="30" COLS="80" WRAP="off"></TEXTAREA>
</FORM>
</BODY>
</HTML>
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should disable the fileName formating

and use relative URL

/Rene
 
Amy Howard
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But how to display files in other directory/driver? This code doesn't work in this case.
 
Rene Larsen
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know - I'm sorry.
/Rene
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
moving this to the javascript forum.
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to do it in html page, there is a limitation - files should be in the same domain.
In NS you could "kind of" go over it with LiveConnect - but user will get a confirm dialog box.
If you want to use HTA files - you could load some files into hidden iframe and use innerHTML propertie, to get file content.
Also you could try to use FileSystemObject script object. Look at http://msdn.microsoft.com under Web Development/Scripting/Script runtime.
 
reply
    Bookmark Topic Watch Topic
  • New Topic