iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-31-2009, 03:48 AM
WebProWorld New Member
 
Join Date: Oct 2009
Posts: 2
Bips123 RepRank 0
Default How to open and save text files using Javascript ?

Hi
First of all, let me tell you that this is not a homework question, since i am no longer in college, i don't get homework.

Ok now to the question => Can you please give me a little example java script to open and save text files

Thank you in advance
Reply With Quote
  #2 (permalink)  
Old 10-31-2009, 09:52 AM
DaveSawers's Avatar
WebProWorld Veteran
 
Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 492
DaveSawers RepRank 3DaveSawers RepRank 3
Default Re: How to open and save text files using Javascript ?

No. Javascript has no access to the file system on your computer. This is for security reasons to prevent web sites hoovering up your local files.

You can use scripting (e.g. PHP) that runs on the web server and reads or writes files there and you can use Javascript (AJAX) to call back to the server to get the information you want from those files.
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
  #3 (permalink)  
Old 10-31-2009, 12:27 PM
WebProWorld New Member
 
Join Date: Sep 2009
Posts: 13
freezea RepRank 0
Default Re: How to open and save text files using Javascript ?

If the file is on the same server, you can read it using XHR and use the responseText property to get at the contents. If you’re a prototype user, it would look like this:
new Ajax.Request(‘myfile.txt’, {
onComplete: function (transport) {
alert(transport.responseText);
}
});
Reply With Quote
  #4 (permalink)  
Old 10-31-2009, 08:54 PM
danlefree's Avatar
WebProWorld Pro
 
Join Date: Jun 2005
Location: Seattle
Posts: 269
danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4danlefree RepRank 4
Default Re: How to open and save text files using Javascript ?

Microsoft allows JScript to access the operating system shell to perform commands on the local machine - though I wouldn't recommend using this technique for websites as the browser will either ignore the script, throw errors, or present users with an ominous security dialog.
__________________
Dan LeFree | Product Manager (Linux VPS Hosting) | Owner/Operator (Web development, marketing)
Reply With Quote
  #5 (permalink)  
Old 10-31-2009, 09:11 PM
Uncle Dog's Avatar
WebProWorld Pro
 
Join Date: Apr 2008
Location: Scotland
Posts: 268
Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5
Default Re: How to open and save text files using Javascript ?

If you are looking for a way to preserve data between site visits - you could use JavaScript to create a cookie. It can contain roughly 4Kb, that's quite a lot of text.
__________________
There are 10 types of people in this world: those who understand binary and those who don't.
Reply With Quote
  #6 (permalink)  
Old 11-02-2009, 09:48 AM
morestar's Avatar
WebProWorld Veteran
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 991
morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5
Default Re: How to open and save text files using Javascript ?

as freezea sort of mentioned...you could use ajax which stands for asynchronous JavaScript + XML.

I'm not sure if you can open text files but I believe you can. If not someone else will clarify this for you.

The only thing is you're going to have to find a ajax script that sort of does what you want and hack (edit) it to your desires.
__________________
Join free dating sites and meet single people without paying a penny.
Reply With Quote
  #7 (permalink)  
Old 11-02-2009, 02:02 PM
Uncle Dog's Avatar
WebProWorld Pro
 
Join Date: Apr 2008
Location: Scotland
Posts: 268
Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5Uncle Dog RepRank 5
Default Re: How to open and save text files using Javascript ?

...and we've all jumped in and assumed you meant JavaScript (looking at your post maybe you meant Java). What exactly do you need to do with this NOT homework.
__________________
There are 10 types of people in this world: those who understand binary and those who don't.
Reply With Quote
  #8 (permalink)  
Old 11-02-2009, 02:07 PM
morestar's Avatar
WebProWorld Veteran
WebProWorld MVP
 
Join Date: Jun 2007
Location: Burlington, Ontario (Toronto)
Posts: 991
morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5morestar RepRank 5
Default Re: How to open and save text files using Javascript ?

Quote:
Originally Posted by morestar View Post
as freezea sort of mentioned...you could use ajax which stands for asynchronous JavaScript + XML.

I'm not sure if you can open text files but I believe you can. If not someone else will clarify this for you.

The only thing is you're going to have to find a ajax script that sort of does what you want and hack (edit) it to your desires.

wow, actually you can't open a local text file with ajax...I just searched around and found nothing that proves you can either...

my wrong...
__________________
Join free dating sites and meet single people without paying a penny.
Reply With Quote
  #9 (permalink)  
Old 11-02-2009, 03:34 PM
DaveSawers's Avatar
WebProWorld Veteran
 
Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 492
DaveSawers RepRank 3DaveSawers RepRank 3
Default Re: How to open and save text files using Javascript ?

Quote:
Originally Posted by morestar View Post
wow, actually you can't open a local text file with ajax...
You can't do any file stuff on the client because it would be an horrendous security violation. It is possible to get access to the clipboard on the client, although this too should be totally blocked for security reasons. If you use Firefox, they quite rightly make it extremely difficult to allow. If you are an IE user, you can let any web site have access to your clipboard simply by answering yes to the alert that pops up when something tries to access your clipboard!

You can do all file operations on the server using AJAX; save and read files there and pass the contents down to the client.
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
  #10 (permalink)  
Old 11-14-2009, 03:06 PM
WebProWorld New Member
 
Join Date: Sep 2009
Posts: 13
freezea RepRank 0
Default Re: How to open and save text files using Javascript ?

In my opinion, you should refer to the url below:
How to read and write files in JavaScript

Reading / Writing a text file? - JavaScript / Ajax / DHTML answers

Can javascript open and write to a text file? - windows - JavaScript - Forums at ProgrammersHeaven.com
Reply With Quote
  #11 (permalink)  
Old 11-14-2009, 04:39 PM
DaveSawers's Avatar
WebProWorld Veteran
 
Join Date: Dec 2006
Location: Calgary, Alberta, Canada
Posts: 492
DaveSawers RepRank 3DaveSawers RepRank 3
Default Re: How to open and save text files using Javascript ?

Hmm.

Except your first link says use an ActiveX control (which is nothing to do with Javascript).

Your second and third links basically reiterate what has been said above.
__________________
Dynamic Software Development
www.activeminds.ca
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can Flash files open up in own window Photoartomation Graphics & Design Discussion Forum 6 09-17-2009 11:55 AM
JavaScript Remote Scripting: Processing XML Files WPW_Feedbot Graphics & Design Discussion Forum 0 10-10-2005 04:09 AM
Windows 2000 Slow with File Open and File Save Dialog Boxes steve0 IT Discussion Forum 2 09-15-2005 06:27 PM
Will Text Ads Save Broadband Content Partnerships? WPW_Feedbot Marketing Strategies Discussion Forum 0 01-18-2005 05:30 PM
Does PS save support .bak files? matauri Graphics & Design Discussion Forum 1 05-10-2004 06:06 PM


All times are GMT -4. The time now is 10:36 AM.



Search Engine Optimization by vBSEO 3.3.0