JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2057
Number of posts: 5155

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Can you do this with JS? Posted by Dab1969 on 30 Mar 2004 at 2:23 PM
Say you have a HTML Forms page and you want to take the data that is entered on that page and save it to the users hard drive, but in a comma delimited text file. Can JS be used for this?? If so, could someone provide some examples please??

Thanks
David
Report
Re: Can you do this with JS? Posted by zibadian on 30 Mar 2004 at 9:40 PM
: Say you have a HTML Forms page and you want to take the data that is entered on that page and save it to the users hard drive, but in a comma delimited text file. Can JS be used for this?? If so, could someone provide some examples please??
:
: Thanks
: David
:
No, that would be considered a major security hole. In addition, any HTML page could write a virus to any-one's harddisk.
Report
yes JavaScript can save files Posted by Josh Code on 1 May 2004 at 9:03 AM
This message was edited by Josh Code at 2004-5-1 9:17:44

: Say you have a HTML Forms page and you want to take the data that is entered on that page and save it to the users hard drive, but in a comma delimited text file. Can JS be used for this?? If so, could someone provide some examples please??
:
: Thanks
: David
:

You can write files to a person's harddrive. To deal with security problems, the viewer of the page will always be asked for permission to make the file, however.

JScript(something made by Microsoft) has a File object that you can use.

There are ActiveX objects to use. Click the link below for a reading example.
http://www.theserverside.com/discussions/thread.tss?thread_id=18599
This object can also be used for writing files.

take a look at this too.
http://www.webreference.com/js/tips/001031.html

I tried it out with Netscape and Internet Explorer and it only worked for Internet Explorer.

Here is the code I used:
<html>
<SCRIPT LANGUAGE="JavaScript">
<!--

function WriteFile()
{
	var TristateFalse = 0;
	var ForWriting = 2;
		myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
		myActiveXObject.CreateTextFile("c:\\test.txt");
		file = myActiveXObject.GetFile("c:\\test.txt");
		text = file.OpenAsTextStream(ForWriting, TristateFalse);
		text.Write("Hello World");
		text.Close();

}

// -->
</SCRIPT>
<body onload="WriteFile()">
</body>
</html>

Report
Re: yes JavaScript can save files Posted by Weirdofreak on 2 May 2004 at 1:45 AM
ActiveX is IE-only (I'm not sure if IE Mac works, but who uses that when there's Safari?), and I'm pretty sure you need a plugin, although it's one that comes by default.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.