Is it possible to write javascript to display files in textarea?
Amy Howard
Ranch Hand
Joined: Jul 11, 2002
Posts: 86
posted
0
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!
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>
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Yuriy Fuksenko
Ranch Hand
Joined: Feb 02, 2001
Posts: 413
posted
0
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.
subject: Is it possible to write javascript to display files in textarea?