Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7546147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:07:29+00:00 2026-05-30T09:07:29+00:00

Do any one have a sample code of how to read and write from/into

  • 0

Do any one have a sample code of how to read and write from/into text file using javascript

What i tried is like created a iframe and load text file into it from iframe i read the content and using string operation make some changes, and i have no idea how to write back to text file.
and also on ie browser this code is not working.

My text.txt file contain
First line
second Line
Third Line
Fourth Line

<html>

<head>
  <title></title>
</head>

<body>
<script language="JavaScript" type="text/javascript">
<!--


var srcFrame;

function loadOuter(doc) {
 srcFrame = document.getElementById("hiddenContent");
 srcFrame.src = doc;



 transferHTML();

}

function transferHTML(){
 srcContent='';
 if (srcFrame.contentDocument){
 alert("document");
  srcContent=srcFrame.contentDocument.getElementsByTagName("BODY")[0].innerHTML;
 }
 else if (srcFrame.contentWindow){
  alert("window");
  srcContent=srcFrame.contentWindow.document.body.innerHTML;
 }

srcContent.length;
alert(" before push "+srcContent);
var arrayText="Last Line";
var lines = srcContent.split('\n');
lines=lines.slice(0, -1);
lines.push(arrayText,"</pre>");
lines = lines.join('\n');
srcContent=lines;
alert(srcContent);
document.getElementById("outerDisplay").innerHTML = srcContent;
}

</script>

<INPUT TYPE="button" VALUE="Test.txt" onClick="loadOuter('Test.txt')" >

<div id="outerDisplay"></div>

<iframe  id="hiddenContent" width="200" height="200" style="position:absolute;visibility:hidden;" ></iframe>

</body>

</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:07:31+00:00Added an answer on May 30, 2026 at 9:07 am

    In IE this is possible using ActiveXObject and HTA. These, however, are recommended to use local only, not in the WEB. Look at: http://msdn.microsoft.com/en-us/library/ms536471%28v=vs.85%29.aspx

    More info for file operations: http://msdn.microsoft.com/en-us/library/bstcxhf7%28v=vs.84%29.aspx

    Basic functions below:

    ActiveXObject definition:

    fso=new ActiveXObject('Scripting.FileSystemObject');
    

    Reading file:

    iStream=fso.OpenTextFile('filePath',1,false);
    iStream.ReadAll();
    /* or looped iStream.ReadLine() */
    iStream.Close();
    

    Writing file:

    oStream=fso.OpenTextFile('filePath',2,true);
    oStream.WriteLine(/*your_data*/);// This usually is looped according to your data
    oStream.Close();
    

    fso-object can also be used in regular HTM-page, but you’re asked to accept use of the ActiveXObject very often.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have some sample code showing how to POST to a URL using
Someone have any sample of Comet app .net? I need one sample how to
Does anyone have sample code to copy open (in-use and locked by another program)
Does anyone have sample code, or a tutorial which demonstrates how to use Grappa
Has anyone tried the ActiveRecord Intro Sample with C# 3.5? I somehow have the
i have read the thread Google Goggles API . and From NotAnotherCodeBlog have created
Matlab is failing to read in the specified number of elements from a file.
I have some code that puts new text on first line of a text
It is easy to read an XML file and get the exact Node Text,
I have a very simple web application that have to read and write in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.