[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

javascript write TXT or Word document

Posted on 2007-07-23
10
Medium Priority
?
1,000 Views
Last Modified: 2012-06-27
Hi,
I want to write a txt file, word or Xls document from javascript

can you help me?
I tried this
******************************************************************************************************************
<html>
<head><title></title>


<SCRIPT LANGUAGE="JavaScript">
function WriteToFile(sText)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var FileObject = fso.OpenTextFile("C:\\LogFile.cvs", 8, true,0); // 8=append, true=create if not exist, 0 = ASCII
FileObject.write(sText)
FileObject.close()
}</SCRIPT>

<br>
</head>
<body>
<A HREF="javascript:WriteToFile('sdsdsd.ewewewewe,ererere')">Crear documento</A>
</body>
</html>
******************************************************************************************************************
It sends an error "ActiveXObject is not defined"
0
Comment
Question by:Iamme
9 Comments
 
LVL 17

Accepted Solution

by:
gops1 earned 172 total points
ID: 19549569
Mozilla or Netscape or FireFox browsers do not allow access to the local file system for security reasons.
0
 
LVL 54

Assisted Solution

by:b0lsc0tt
b0lsc0tt earned 164 total points
ID: 19549716
Those browsers don't even support ActiveX.  Is this in IE or another browser?  The code above will only work in IE but it won't work on an Internet page with default security settings.  Is this an intranet page or one on a website and Internet (look at the bottom, right part of IE to see how it treats the page).

Let me know more about the page and I can see about suggesting a security setting change but if this is for a public webpage you will not get it to work.  Users and the browser won't want to allow that type of action.

Let me know if you have a question or need more info.

bol
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 164 total points
ID: 19549748
IE will, especially if you give it an extension of .HTA

Also use this:
<A HREF="#" onClick="WriteToFile('sdsdsd.ewewewewe,ererere');
return false">Crear documento</A>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 19549768
By the way, this is usually done with server side script and using the server objects.  You will not have the security (user's computer and browser) restrictions doing it on the server.  The server can even send the txt or other file to the browser after it is created.  You could even use server side Javascript if you want.  The key is the browser won't allow webpages to make files, open them, etc on the client's computer.

If you can use a server language and need help with doing this on the server then let us know.

bol
0
 
LVL 15

Expert Comment

by:deepaknet
ID: 19554006
1) ActiveX is supported only by MSIE
2) Even within IE, "Scripting.FileSystemObject"  has strong waves of restrictions for security reasons.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 19557428
@Deepaknet - Nice summary but seems to repeat me (http:#19549716).

bol
0
 

Author Comment

by:Iamme
ID: 19794569
I want to delete this question.....
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 19794980
Iamme,

Why?  What is the status of this and how did any of the comments above help?

bol
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20031910
Forced accept.

Computer101
EE Admin
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

834 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