3

I have a requirement which i need some input on, I am using a very outdated version of xojo for a legacy application, the requirement is i need to open a webpage on the users system which isn't connected to the internet!

So i have a folder containing a website on its entirety, when i open the index.html file it loads all the resources locally and does not require anything to be download or access the internet.

Now on this website the user performs some actions like a survey or a guide as an example and i need to record all these actions and store it on a file so that later when the user is connected to the internet i can upload the files to the server.

How can i write json data to a file on the users pc via IE/Chrome/Firefox/Safari using javascript? Any ideas will be helpful.

Ratan Servegar
  • 375
  • 1
  • 6
  • 21
  • Is there a reason they're not online, or is it just poor connectivity? There's typically no way to write a file to the file system directly from a browser (it's a bit of a security risk) without prompting them to download a file. – phuzi Nov 15 '18 at 15:11
  • There is, they use this legacy application in a no internet environment at certain client locations, is there a way to write to a already existing file in the local folder where the html file is located? – Ratan Servegar Nov 15 '18 at 15:43
  • Creating files and saving it in storage is a server side act. Your application is similar to browser itself. So it can not be done directly. You have to access server side resources of that device. – Love Buddha Nov 15 '18 at 15:57
  • It sounds like you'd be better off writing a desktop application for your purposes. – phuzi Nov 15 '18 at 16:13
  • you could possibly use an alternative mechanism like localStorage within the browser. But it will only end up being uploaded to the server if the user actually opens the same page again while connected to the net...and you might still have issues with things like CORS if it's not running in a proper http environment. You'd be better off with a proper thick-client app (i.e. desktop application) and maybe a background service to do the syncing – ADyson Nov 15 '18 at 16:15
  • Putting the page into an electron app would be worth looking into – charlietfl Nov 15 '18 at 16:18
  • @charlietfl electron would let me write to a file even though it uses js ? – Ratan Servegar Nov 15 '18 at 16:28
  • Yes. It has internal node.js server and runs as desktop app – charlietfl Nov 15 '18 at 16:30
  • @charlietfl Thanks ill look into it. – Ratan Servegar Nov 15 '18 at 16:31

1 Answers1

1

You can only emulate a download, direct writing to local disk is not allowed.

See this post for possible answer:

Download JSON object as a file from browser

Marc
  • 5,109
  • 2
  • 32
  • 41
  • So what your saying is i can use js to create a json object and have that downloaded to disk? will it require the user to manually save it to a location? or can i specify the location to where the file has to be saved? – Ratan Servegar Nov 15 '18 at 15:46
  • User will have to manually save it. Actually i just remembered my cousin had a similar case to yours, mentioned an issue where reading in files from local disk is not allowed either when running an html file out of a directory directly. He created an SPA using Spring Framework as a service the user could run locally. https://spring.io/ – Marc Nov 15 '18 at 15:56
  • I think he used Spring Boot https://spring.io/projects/spring-boot – Marc Nov 15 '18 at 16:02