Skip to main content
GameDev.net gamedev.net
🔒 Locked

[web] Can javascript open files?

Started by GameMasterXL Sep 26, 2005 at 2:39 PM 8 replies 14.1k views
Original Post
GameMasterXL
GameMasterXL
Can &#106avascript open a text file? or can i transfere data within a text file into my.html page so the data gets sent into my textarea, so like i have a file called .hsc and when i click it i want that files contents to be sent to my .html textarea is this possible? just like .txt files send data to notepad.exe.
aidan_walsh
aidan_walsh
&#106avascript under IE can manipulate ActiveX components to open and read files, but I'm pretty sure that the ECMAScript standard doesn't have anything like that, so it wouldn't be portable.
www.aidanwalsh(.net)(.info)
GameMasterXL
GameMasterXL
S0 does this mean i will have to re-write it in C#?
fur
fur
Mozilla/FireFox has jslib which includes file i/o libraries.
http://www.p2pmud.com
markr
markr
Quote:
Original post by GameMasterXL
Can &#106avascript open a text file? <br><!--QUOTE--></td></tr></table></BLOCKQUOTE><!--/QUOTE--><!--ENDQUOTE--><br><br>Yes and no.<br><br>You can't open a local file in unprivileged web-browser code (which is what you are probably talking about).<br><br>You can read remote files (subject to security restrictions) using XMLHttpRequest.<br><br><!--QUOTE--><BLOCKQUOTE><span class="smallfont">Quote:</span><table border=0 cellpadding=4 cellspacing=0 width="95%"><tr><td class=quote><!--/QUOTE--><!--STARTQUOTE--><br>or can i transfere data within a text file into my.html page so the data gets sent into my textarea, so like i have a file called .hsc and when i click it i want that files contents to be sent to my .html textarea is this possible? <!--QUOTE--></td></tr></table></BLOCKQUOTE><!--/QUOTE--><!--ENDQUOTE--><br><br>Not totally sure what you're getting at here.<br><br>You can certainly read a remote file into an IFRAME element. You can read a remote file with XMLHttpRequest and put its contents into a textarea. You can do various other things.<br><br>Perhaps it would be better for you to tell us what you're trying to achieve and we can suggest solutions. Most of them are likely to involve server-side code.<br><br>Mark</td></tr></table></blockquote>
GameMasterXL
GameMasterXL
This program will be a client side scripting program that i am creating for halo ce. So is what i am wanting is when i click on the file that has an exention of type .hsc then it will send its contents into the textarea of my program and open it up just like notepad opens when you click on a .txt file. So i am wanting my file to be loaded into my program and open it up to view it so you can edit the source of the script ect.
ArchG
ArchG
Hrmm..What I would do..

Is look into the XMLHttpRequest object in &#106avascript (as markr mentioned)...what you can have that do, is run an ASP.net script (ASP can look into that file if it's on the webserver) that sends the contents of the file back to the page, and load it into the textbox.<br/><br/>If you need help with the XMLHttpRequest Object, let me know..I recently made a web app that does something similar except it reads and executes SQL statements instead of opening a file
commando_337
commando_337
Quote:
Original post by GameMasterXL
This program will be a client side scripting program that i am creating for halo ce. So is what i am wanting is when i click on the file that has an exention of type .hsc then it will send its contents into the textarea of my program and open it up just like notepad opens when you click on a .txt file. So i am wanting my file to be loaded into my program and open it up to view it so you can edit the source of the script ect.


I think that if I'm understand you here, all you are looking for is how to associate your .hsc files with Internet Explorer, right? That way when you open My Documents (As an example) and see all of your .hsc files you can double click it and have it open directly in IE.

What you are looking for is right in the Tools menu within My Computer.
Go Tools->Folder Options then select the "File Types" tab at the top. You will now have to create a new association between files with the .hsc extension and Internet Explorer.

Is this all that you needed?


===

Commando_337
Sander
Sander
No need to fuss about with XmlHttpRequest specifically (though it could make for a slick interface [smile]). The easiest way is to have a simple file upload form that sends the hcs file to the server, then have the server put out a page with a textarea box containing that file's contents in it. This means you will need some kind of serverside scripting (PHP, Perl/CGI, etcetera). What serverside scripting (if any) does your host allow? Or are you trying to make this work from a html page that resides on your own computer?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.