0

I'm working on a website that is going to be offline. All the html files will be in a folder stored on the hard-disc. I've managed to do 90% of the work and the last part I have no idea of. Here is what it is:

I have stored a list of products in the localStorage as various strings under the keys - like buying objects and it goes to the cart, the cart objects are in localStorage. I created a page that showed the list of all the products in the localStorage. It can be cleared if the user clears them. Now I need to create a page where all the objects that was selected before, regardless of the localStorage being cleared, show as list in this page. You can take it as the page that lists products that have been ordered in the past, i.e even after the cart is cleared the products will show in the past-orders page.

I do not know any server side codes, I did everything using JavaScript as it was supposed to be a simple project, but I'm stuck at this part. So I cannot use PHP or anything to generate files or use a database to store stuff.

Here's what I thought but I don't think it works but wanted to confirm if it does or not: Generate an XML file or a .txt file and store it in the drive and then clear the localStorage. But I don't think it is possible. If its possible just using JavaScript please point me in the right direction and I'll research and come up with something.

P.S. the website will be entirely offline what I mean is the users will never connect to the internet for this to work. Also there won't be a server or localhost.

Thank you!

The site is completely offline, but functionality is similar to an eCommerce site. You click a button and some content from the website stores in the localStorage and I have to call it in multiple pages, when a user clicks another button, localStorage clears but whatever was selected before must be available without localStorage. Hmmmm.. Consider a quiz site where you answer everything and when you take a new quiz, old scores will be stored somewhere else and it won't change when you take a new test.

Is it possible to attain this functionality without a server side script? It seems the final-targeted-users won't know how to install any softwares that can provide a localhost or a server or something like that.

Renuka
  • 28
  • 4
  • And save directly to a folder? JavaScript can't access the local filesystem for very good security reasons. You could potentially make a file available to them for download, see: http://stackoverflow.com/questions/2897619/using-html5-javascript-to-generate-and-save-a-file?rq=1 – Evan Knowles Sep 15 '14 at 06:11
  • "like buying objects" doesn't sound an off-line application. I mean how to buy anything when off-line? – Teemu Sep 15 '14 at 06:18
  • you can save it in the downloads folder, but not just any old folder. well, actually, some browsers provide an option to "ask where to save each time", so in that manner any folder could be saved to... http://danml.com/download.html – dandavis Sep 15 '14 at 06:41
  • @Teemu That was just an example, its totally offline you don't exactly buy stuff in this website, but the functionality is similar. – Renuka Sep 15 '14 at 09:23
  • @EvanKnowles I thought about the download method, but then if the end users save the file elsewhere or won't download it at all, that'll be a problem. Also getting the URL where they downloaded it and calling that in my code is bit too advanced for me (Idk if its possible). Thanks for commenting! :) – Renuka Sep 15 '14 at 09:35
  • @dandavis sorry i can't tag more than one person it seems so please check my previous comment. – Renuka Sep 15 '14 at 09:35

2 Answers2

0

Client-side, browser's JavaScript runtimes don't have local file system access excepting a very limited one when uploading files to a remote server, and anyway, browers won't give you direct access to the file.

You'll need some kind of server-side logic behind the scenes if you want full I/O in the local file system.

Perhaps you can take a look at NodeJS, a server-side JavaScript runtime that can work as lighty Web server on either small and large projects, and it has built-in server-side JavaScript I/O functions.

Otherwise, you're absolutely stuck in the client-side Web browser's sandbox limitations.

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
0

U can refer documents of knockoutjs and NodeJS.. That would probablky help... A far as my knowledger is concerned NodeJS does contain a way to handle your problem.

jyotin
  • 48
  • 8