![]() |
Javascript code to create a text file
<html>This code doesn't work, it throws error Uncaught ReferenceError: ActiveXObject is not defined When opened in google chrome version 24.0.1312.52 m Can anyone help on this. Moto of this code is to create a text file with some content using javascript |
thats becuase activex only works in internet explorer
|
Tried but didnt work
Quote:
Thanks for the reply. I tried with internet explorer, but it throws error as below. When i try with Mozilla firefox with that add on firebug. It throws error as ReferenceError: createFile is not defined Could you please help me to modify the code so that it works, if the code is having problem. My intention is create a webpage with some form and controls, once the user open the webpage (with the use of webpage file anywhere) and fills the data in the form and click submit button, a notepad file should be saved in his local drive under defined path. No client/server communication. |
JavaScript cannot safe files on the client's computer. A nice tool to use is Downloadify ( https://github.com/dcneiner/Downloadify ). It's a little Flash application that you can easily style as a button. Using JavaScript you can feed it with a text and then by clicking on it it will allow the user to save the file.
air |
Airblader is very very wrong.
MSIE *CAN* save files on the client computer. Providing that the user allows it to by setting the security settings. There is nothing wrong with the JS code as shown in that first post. The error about "unterminated string constant" is simply not true. So ssen must have changed the code before trying it with MSIE. Now, having said all that... The code will almost surely not run. First of all, unless SSEN has changed the security settings in his MSIE browser, he won't be allowed to create the FileSystemObject. Secondly, it is very unlikely that the browser will have permission to create a file in the C:\ directory. SSEN should be using some sub-directory that is used for *NOTHING* except junk file like this and that is marked as WRITABLE by the browser. |
I have to say that it worked for me in IE9, with a warning message.
See also http://www.codingforums.com/showthread.php?t=262759 |
Quote:
air |
Okay, then, Airblader. Let's just say your answer is irrelevant.
Of course you are right in the general case of all browsers. But... Because *CLEARLY* this line in his code: Code:
var object = new ActiveXObject("Scripting.FileSystemObject");So giving an answer that is not MSIE-only is irrelevant to his code. |
I took it as him just copying something he found somewhere online without knowing that it would only work in MSIE. I know very few examples when something was developed for MSIE and MSIE only – all of which were professional enterprise solutions*.
I think it's not safe to infer from one line of code of a beginner that he wanted to go for a MSIE only solution. Even more so because he was using FireFox. Why would he wonder that it doesn't work in FF if he knew it's MSIE only? *) Although you could argue that MSIE and "professional" are opposites. air |
OMG! You are *SO RIGHT* Airblader!
I am an utter DOOFUS! Or at the very least I am blind! (Almost true, this week...one of my eyes has triple vision temporarily.) I *UTTERLY MISSED*: Quote:
|
You certainly are being childish ... rendering this discussion useless. The last time I checked Google Chrome wasn't the same as MSIE, so my point is still valid. Besides, it doesn't even matter – he never specifically asked for MSIE-only compatibility and I didn't see enough reason to infer it from his posting, so I provided a cross-browser solution.
|
What? I am admitting that I completely blew my answer. It was *MY* answer that was completely irrelevant, not yours. Why does that bother you?
|
this works great in chrome, full FF support should kick in starting early spring:
Code:
function download(strData, strFileName, strMimeType){ |
Quote:
|
Why do you insist on JavaScript? I gave you an alternative that is much more stable. For pure JavaScript to be able to do this cross-browser and reliably you will have to wait – indefinitely.
|
| All times are GMT +1. The time now is 05:47 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.