Saving out a javascript object? - javascript

Is it possible to save out some javascript object purely on client-side?
My question come from the following workflow: a user enters and posts a text, i do some processing on the server side and return processed text to the user. The user can do some modifications to the returned text, if he doesn't like some processed parts of it. Is there any client-side javascript functionality so the user pressed the button 'save' and it pops a save file dialog as if the user downloaded this file from a server? Or I need a server interaction for example to post the results and return them to the users as a file?

You could implement this functionality with a server side functionality, but not with JavaScript. Pressing 'Save' would create an AJAX call to the server which responds with the file correct headers, making the browser respond with a "Save file" dialog.

No. Unassisted JavaScript cannot save files (IE with activeX/WHS can use the file system, mozilla products may have something here which I have not investigated)
But you can popup a window or write it to an iframe which can be printed to for example PDF which is saved on the client

with javascrpipt you don't have access to the filesystem on the clients pc (except of the cookies). so you have to send him a downloadable file.

Related

Store/load data via (private) website on server with dialog box

Searching for a number of questions/answers, I could not find a solution for my application:
I wrote a web application (HTML/JavaScript and some PHP) to read and control an apparatus through RS232. Commands and data can be submitted and received through a simple serial connection. I use a dedicated Raspberry Pi Zero as a webserver. (Internet Of Things application)
I can read data, change it and store it again in the apparatus. So far so good.
Now I want the possibility to store this data, preferably on the raspberry (the server). This is quite simple with fopen/fwrite/fclose you might think... Yes but what I want is a button on my webpage, and when I click that button I want a save/load dialog popping up in which I can either choose a filename or make one up (for saving), and then store a string of (human-readable) hex bytes in a file on the server. I need a 2nd button ´load´ with which I can load such a string from a file on the server and send it to my apparatus.
I´d like a dedicated directory on the server in which I can navigate, all the rest should be blocked from reading/writing. (In /var/www/html/syx/ or /var/www/html/php/syx/, but both open for discussion)
The string of bytes is either 70 bytes long or (bulk dump save/load) 64*70 bytes long. These are settings of the apparatus that I´d like to save.
I´d like to stay on the page that calls the file-dialog if possible, opening a new page would destroy my variables (so I read). Is a pop-up possible?
Now javascript cannot touch the server, and I did not find a save/load dialog box popup for PHP. Is there a simple solution? I´d rather not use a database like SQL.
2nd best would be client-side storage instead of server-side storage, but that is also pretty hard, so it seems...
Regards
Arjen
You could use a Modal Dialog to open the "pop-up" and AJAX calls to run your PHP code to store your data. Take a look at W3.CSS Modal. It is simple to use and has a companion W3.JS lib for the AJAX part.

dynamic scraping in nativescript? need to scrape page, with ability to click html button

do any package exist/ or process exist in native-script, for scraping dynamic content, means ability to click HTML button?
or
do i need to switch to cordova, for this ability?
From what I understand from your question (and subsequent comments) you want to (in a NativeScript app):
Load a website
Select a value in two select boxes
Press the submit button
The big question here is what happens when you press the submit button. Most probably this will result in a POST/PATCH being sent to a server.
The way of solving this would be:
Use the HTTP Module of NativeScript to download the web page.
Use Cheerio (or just plain regular expressions) to get the data needed to render the two select boxes and the URI to where to post the form.
Based on the data from (2) create and populate the two select boxes in NativeScript and save the POST uri somewhere.
Create an "on-submit" function which, based on the select boxes, creates the payload in the format the server wants it and then use HTTP Module again to post it to the URI.
To see the network traffic going on between the client (your browser) and the server, just open up the Networks Panel of your web browser, e.g. for Chrome or Firefox.
Looking at the network data should get tell you where to POST the data and how the payload should look like.
This can, of course, also be seen by looking at the code of the webpage.

I need to generate a JSON file in browser using (currently) javascript

I have a website that allows users to select a date range from a data set. At least, that's the goal.
What I would like to have happen: the user selects a date range, presses the submit button, and a script generates a JSON file which MATLAB reads to generate the graphs.
Any thoughts on resources to help accomplish this?
You'll need the script that fires off to be server side. JavaScript is client side and can not, in any way, access, modify, or otherwise create files on the client. You'll have to use a language like PHP to create the file.
Example using PHP:
Once the file is created, force a request on the client side to fire asking for the file. Set the PHP header to Content-Disposition: attachment; filename="< Place file name here>".
This will prompt the browser to launch a download prompt allowing the user to download the file.
Hope this helps.
You can use Downloadify, a small Flash component with a Javascript interface that allows you to create files on the client that a user can download. That's what I used in a similar situation.
You could also try and use Data URI but they are a quite limited and browser specific so some issues may arise.
These may be alternative solutions to the previous answer that suggested using server side code to generate the file.

How to fill a PDF field in the client-side (Javascript)

I need to create a application that needs to get information from the user using HTML text fields and fill-it to PDF fields. The fill-able PDF can be obtained from the server. The data filled in by the user cannot be submitted to the server (Sensitive information / legal problems). I need a way in which the JavaScript can take the information filled by the user, and fill it to the PDF, and make it available for the user to print/download.
(Initially, I tried to to just have HTML+PRINTCSS and avoid using a PDF, but then I had the issue of headers added by browsers to HTML that is printed. I don't want the worry the user to check his browser print settings - as most of them are computer illiterate)
I don't think this is doable via JavaScript alone. Some PDF readers do support JS, but many do not or allow the user to toggle it, and even then the PDF wouldn't have access to variables in the browser window. You'd be better off pre-filling the fields serverside. PHP in particular has robust PDF handling available out of the box.
You could, for instance, let the user fill in the form online - the "Print" button could use AJAX to submit the form to the server, and point the window at the resulting PDF download link. You could also simply submit the form without JavaScript, and let the server handle the redirection by setting the header.

fetch clipboard data

i need to fetch a Prt Screen Image from the clipboard and save it in the database.
I have never really done the save image in database thing before.
The clipboard lives on the client operating system; unless the user pastes the image into an editor, saves it and uploads it using a form, there's no way you can get that data with HTML and the server side alone.
You can't grab a printscreen of a client by with PHP. PHP is a server side technology and cannot access the client. You'd have to use some kind of client side tech like flash, js or java applet. You might want to retag your question if those are permissible.

Categories