Jump to content
  • Advertisement
Sign in to follow this  
GameMasterXL

Javascript question on file opening

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is my problem i am creating a internet program that uses javascript and is what i want to do is i have this file type that i want to open. Somy file type is .hsc and is what i want is when i click that file i want the contents of the file to be sent to my textarea in my .html page. Is this eaven possible to do? can i pass text files into a .html textarea? I hope someone can help.

Share this post


Link to post
Share on other sites
Advertisement
You usually do not use javascript to open server-side (or even client-side) files. A language like PHP or ASP would be much more suited for this task, I think.

Share this post


Link to post
Share on other sites
No this is not for server, is what i am making is a scripting application in javascript. So is what i was wondering was can i set a file type up so when i click it in windows explorer it sends the file data to the textarea of my javascript application?

like

File -> clicked
|
send data to textarea -> html file -> textarea.

Like in the system registery you can set things up like if you click the file you can send it to a program i am just wondering if i can do this with .html files but put the data into the textarea or do some tricks to get it there is this possible?

Share this post


Link to post
Share on other sites
Use the FileSystemObject; here's an example but for more information check msdn.

Oh, and ActiveX must be enabled on the browser.


function ieLoadFile(filePath)
{
try
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
}
catch(e)
{
//alert("Exception while attempting to load\n\n" + e.toString());
return(null);
}
var file = fso.OpenTextFile(filePath,1);
var content = file.ReadAll();
file.Close();
return(content);
}


Share this post


Link to post
Share on other sites
Wow thanks dude, it is weird C# is so similar to javascript in its functions and syntax. So can i now set the registery up so if i click on my scritp file .hsc in windows explorer it sends the file into the function ieLoadFile()? so i can open my files like you notepad opens .txt files when you click them.

Share this post


Link to post
Share on other sites
I don't know about all that but you can add to a html file an onLoad call to call a javascript function to load the file when you click on the page opening it with internet explorer.

Don't let the similartity fool, javascript (or scripting language covered by the ecma standard) is a very powerful prototype based oo language. Google for 'javascript 1.5 core reference' for more info.

Have fun!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!