admin管理员组文章数量:1297064
Can anyone help me as i am stuck in creating a file(temporary) with extension(say .csv) in the local disk, i tried using ActiveX object but it works fine only in internet explorer,got a error when i tried with other browsers. By googling i got to know ActiveX works only in IE so it produces error when its tried in different browser.
var fso, f1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.GetFile("c:\\test.txt");
alert(f1);
Can anyone suggest me with the alternative which can be very useful to.
Can anyone help me as i am stuck in creating a file(temporary) with extension(say .csv) in the local disk, i tried using ActiveX object but it works fine only in internet explorer,got a error when i tried with other browsers. By googling i got to know ActiveX works only in IE so it produces error when its tried in different browser.
var fso, f1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.GetFile("c:\\test.txt");
alert(f1);
Can anyone suggest me with the alternative which can be very useful to.
Share Improve this question asked Feb 26, 2013 at 10:31 pavanpavan 4703 gold badges11 silver badges25 bronze badges 5- 1 There's no corresponding feature in other browsers. The nearest you can find is probably HTML5 localStorage. – Teemu Commented Feb 26, 2013 at 10:47
- Thanks for the reply,i want to store the data that es from the web service through ajax in a file created in the local disk using javascript. – pavan Commented Feb 26, 2013 at 10:52
- 1 Can I ask why as there may be a better option? If you are calling a web service, I assume you have access to some server side code / scripting where this task may be better suited and be truly cross browser patible. – webnoob Commented Feb 26, 2013 at 10:54
- i want to store the file with .csv extension which can help to open this file using notepad,excel etc. Can you suggest me if there are any better option? – pavan Commented Feb 26, 2013 at 10:57
- I have added an answer with more inforamtion. If you need anything else, post a ment against the answer (to avoid bloating it up here). – webnoob Commented Feb 26, 2013 at 11:09
2 Answers
Reset to default 3The problem you have is that browser implementations of ECMAScript (JavaScript) don't allow you to write to the clients' disk. Microsoft reverse-engineered JavaScript, and dubbed it JScript. Though the base is the same, MS added those ActiveX objects, and a piler (JScript can be piled, yes).
In short, JScript can be used for more than just browser tasks, so MS provided ActiveX objects to enable some form of I/O. The only thing you can do on browsers other than IE, is using HTML5's new DOM Storage objects. Teemu provided a link to the documentation for that
The other posts cover all the information about storing to the local machine using Html 5 so I won't go into any more detail about that but this is only going to work on Html 5 patible browsers (although most browsers are Html 5 patible now, I don't know your project requirements).
Another alternative would be to create / save the file using server side code (ASP.NET, PHP etc) and then provide a link to the user so they can download the file. You can still save this as a .csv file so that the user can open it in Excel after they have downloaded it.
Edit:
What I would do is change your web service so that it saves the file to disc (more info: here). Then instead of returning the file from the web service, return the Url to download it instead. You can then redirect the user to that link using JS.
本文标签: javascriptAlternative for the ActiveX object for the other browsers excluding IEStack Overflow
版权声明:本文标题:javascript - Alternative for the ActiveX object for the other browsers excluding IE? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741619251a2388712.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论