It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Writing using javascipt

Writing using javascipt

Postby karimkhan on Tue Mar 01, 2011 6:31 am

Dear friends ,
I tried to write in html page from text file using
"
<html>
<head>
<script type="text/javascript" language="javascript">
function Read()
{
var Scr = new ActiveXObject("Scripting.FileSystemObject");
var CTF = Scr .OpenTextFile("C:\\123.txt", 1, true);
data = CTF .ReadAll();
document.write(data);
alert(data);
CTF .Close();
}
</script>
</head>
<body onLoad="Read()">
</body>
</html>

"


But the contains of text file getting changed , like if there is

"My name is Karimkhan
I love India "

Then it will write like "My name is Karimkhan i love India"

It ignores multiple spaces and new line character , so what should I do to prevent this...IS THERE ANYTHING LIKE <PRE> TAG IN HTML "?
karimkhan
 
Posts: 2
Joined: Fri Feb 18, 2011 5:30 am

Re: Writing using javascipt

Postby bardonw on Mon Apr 11, 2011 7:13 pm

Try the following:
Code: Select all
<html>
<head>
<script type="text/JavaScript">

function Read()
{
var Scr = new ActiveXObject("Scripting.FileSystemObject");
var CTF = Scr .OpenTextFile("C:\\123.txt", 1, true);
data = CTF .ReadAll();
document.getElementById("txtFile").value = data;
alert(data);
CTF .Close();
}
</script>
</head>
<body onLoad="Read()">
<p>The file contents are as follows:</p>
<textarea id="txtFile" cols="80" rows="30">
</textarea>
</body>
</html>


Once the local page loads, the file is read and the contents are placed in the textarea. It is important that you can only be sure that this will work on your local machine in Internet Explorer. Alternatively, you can change the extension of the web page to be HTA so that it will not ask you for permissions every time you open the page.
bardonw
 
Posts: 7
Joined: Tue Feb 15, 2011 4:16 pm


Who is online

Users browsing this forum: No registered users and 5 guests