Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Read a system file from javascript

Posted on 2008-06-16
1
Medium Priority
?
181 Views
Last Modified: 2011-10-19
Hello

Could anyone say to me if it's possible to create a javascript code which reads a text file and fill an array with the lines contained in it?


Thanks in advance
0
Comment
Question by:Federico_Ruiz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
ravinadiminti earned 1500 total points
ID: 21796352
Check the code snippet below, the html/javascript code reads 2 files from the C: drive. If you are working on Unix or Linux, change the path of the file accordingly.

Hope this helps
<html>
 
<head>
  <title></title>
</head>
 
<body>
<script language="JavaScript" type="text/javascript">
<!--
var srcFrame;
//External content into a layer
function loadOuter(doc) {
 srcFrame = document.getElementById("hiddenContent");
 srcFrame.src = doc;
 // workaround for missing onLoad event in IFRAME for NN6
 if (!srcFrame.onload) {
  setTimeout("transferHTML()", 1000)
 }
}
 
function transferHTML(){
 srcContent='';
 if (srcFrame.contentDocument){
  srcContent=srcFrame.contentDocument.getElementsByTagName("BODY")[0].innerHTML;
 }
 else if (srcFrame.contentWindow){
  srcContent=srcFrame.contentWindow.document.body.innerHTML;
 }
 document.getElementById("outerDisplay").innerHTML = srcContent
}
 
 
var DocAry=new Array('text1.txt','text2.txt');
 
function SelectList(v){
 if (v>0){
  loadOuter(DocAry[v-1]);
 }
}
 
//-->
</script>
 
<INPUT TYPE="button" VALUE="text1.txt" onClick="loadOuter('C:\\text1.txt')" >
<INPUT TYPE="button" VALUE="text2.txt" onClick="loadOuter('C:\\text2.txt')" >
<br>
 
<div id="outerDisplay"></div>
 
<iframe  id="hiddenContent" width="200" height="200" style="position:absolute;visibility:hidden;" ></iframe>
 
</body>
 
</html>

Open in new window

text1.txt
text2.txt
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question