Jump to content
jamesadrian

Writing a java script on the desktop off line

Recommended Posts

I am just starting to learn some java script. I am looking for a way to write a script on my desktop (which I have done) and see it work on two files on my desktop. I have only seen java script work on my website.

 

Thank you for your help.

 

Jim Adrian

Share this post


Link to post
Share on other sites

You can do it all in one file.

<!DOCTYPE html>
<head lang="en">
<meta charset="UTF-8">
<title>test</title>
<style>
h1{color:red}
</style>
</head>

<body>

<h1>TEST</h1>

<div id="msg">
</div>

<script>
var str = "<b>Hello World!</b>";
document.getElementById('msg').innerHTML = str;
</script>

</body>
</html>

Share this post


Link to post
Share on other sites

When you say on your desktop, what do you mean? A native application or running in a web browser?

Share this post


Link to post
Share on other sites

I have copied the code given above into a text editor and gave it the name test.htm and when I have it on my desktop and click on it my browser renders it as a local file without going on line. This is great!

 

I hope that I can make a few text files and have a script in test.htm manipulate data in the files on my desktop. Of course I will need to know much more javascript to do that. I am willing to learn it all if this goal can be done.

 

Will any additional software be needed in order to do this?

 

Thank you for your help.

 

 

Jim Adrian

Share this post


Link to post
Share on other sites

You may need to change your browser's security settings, I believe that files running locally cannot send requests for other files by default.

Share this post


Link to post
Share on other sites

They can load Javascript files with the script tag, but AJAX requests are blocked.

Share this post


Link to post
Share on other sites

Is this just for something you are doing on your own, or something you are looking to share with other people, so they can run it too?

Share this post


Link to post
Share on other sites

Is this just for something you are doing on your own, or something you are looking to share with other people, so they can run it too?

 

I want to write programs that other people can run on their desktop.

 

Does anything prevent this?

 

Thank you for your help.

 

Jim Adrian

Edited by jamesadrian

Share this post


Link to post
Share on other sites

No, that's not a problem per se. It's just that writing code and distributing code are different objectives and often involve different skill sets, especially if you are specifically targeting desktop users. That said, it's more of a disclaimer is all.

 

Have you heard of Node? It is a JavaScript runtime (akin to what you get when running JavaScript in the browser) except that it is a program that you can have your users install ahead of time and can be run on their own machines, like a native app. From there, you could publish this project to NPM and then users could also use it to install your project (with all its source and dependencies) and from there a single command could be run in order to launch your app.

 

Any reason you are favoring desktop vs. the web though?

Share this post


Link to post
Share on other sites

No, that's not a problem per se. It's just that writing code and distributing code are different objectives and often involve different skill sets, especially if you are specifically targeting desktop users. That said, it's more of a disclaimer is all.

 

Have you heard of Node? It is a JavaScript runtime (akin to what you get when running JavaScript in the browser) except that it is a program that you can have your users install ahead of time and can be run on their own machines, like a native app. From there, you could publish this project to NPM and then users could also use it to install your project (with all its source and dependencies) and from there a single command could be run in order to launch your app.

 

Any reason you are favoring desktop vs. the web though?

I want the simplest way for users to use the program. I would like to email it to them and have it run without any other downloading or complications on their desktop.

 

Can this be done?

 

Jim Adrian

Share this post


Link to post
Share on other sites

If that's what you're going for then Javascript might not be the best tool. What kinds of things do you want the program to do?

Share this post


Link to post
Share on other sites

Moderator,

 

I want the program to take a byte from file A, and another from file B, and use an arithmetic or logical operation on the two bytes and place the result in file C.

 

All three files would be offline, possibly in a folder on the desktop.

 

The program would need to increment the byte address in all cases.

 

I don't care what I would need to use as names of the files or what file types might be used, so long as any eight bits would work as a byte.

 

I would not appreciate a severe limit on the size of these files. One megabyte might be acceptable.

 

If I can't create a file with the script, I would e happy to create them before the script is run.

 

If file C happens to contain only ASCII characters that can theoretically be displayed, I would hope there would be a way to display them or use file C as a text file after the fact (after the script has run).

 

Secondarily, it would be nice if I could interleave a file or use one file to determine a permutation of another file.

 

Thank you for your help.

 

Jim Adrian

Share this post


Link to post
Share on other sites

You should look into a real programming language like C++, Java or something of the sort. Javascript can only read files in particular cases and it cannot write to any files. On a desktop it is even more limited.

Share this post


Link to post
Share on other sites

I would suggest Java. You can download the JDK and a developer IDE here...

 

http://www.oracle.com/technetwork/java/javase/downloads/jdk-netbeans-jsp-142931.html

 

For security reasons Javascript is severely restricted when it comes to accessing files.

 

Other options would be C# or Python. C++ is rather old and clunky.

Share this post


Link to post
Share on other sites

I think the important thing here to keep in mind for the OP is not just looking for development environment, but simple distribution pipeline as well.

 

For that reason, I would still recommend Node. You can continue to write in JS, there are installers for Windows / OSX that anybody can install from to keep that overhead low, and it comes with a package manager. On top of that, you can use Node / NPM to install a webserver for users as well. All in all, it provides a very robust ecosystem for developers, and a pretty straightforward consumption process for users.

Share this post


Link to post
Share on other sites

It seems like a little bit of overkill. It would be pretty simple to write a small C program to do that, compile it into an executable, and send it to people.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...