HTML to run javascript even when page is closed - javascript

Okay, this is a problem I have been having for sometime now, and I cant find a solution, Anywhere!
My Problem:
My HTML content is available as web application that can be used offline, but I want the contact form to also be available offline.
Is there anyway the user can fill in the contact form when they have no connection and then for a script to run that holds that inputted data until a connection is established.
And then once the connection is established for the data to be sent to a PHP script on a server?
Edit:
Thanks for all your answers! I have looked into local storage but this doesnt work as the user may revist the page but they still probably wont have an internet connection, so I was wondering if there is any type of script that can run locally all the time until there is an established internet connection
Thank you in advance!

You can not run a script unless the page is opened.
The only way around this would be to create a Chrome Extention or FireFox Addon:
http://en.wikipedia.org/wiki/Google_Chrome_Extensions
http://en.wikipedia.org/wiki/Add-on_(Mozilla)

Yes - provided that they open your page again with an internet connection at a later date.
The steps are:-
Try and send message (AJAX etc.)
If it fails due to no connection - store to localstorage.
Have a loop that checks for messages in local storage.
If message found try to re-send.
Once message is sent remove it from local storage. (AJAX success)

That is indeed possible if the website stays open.
You can have a javascript loop that checks some recource (i.e. a tiny json file on your server) and if it can read this successfully, it attempts to send the email/data.
If it is not, it waits for a certain time using timeout.
You'll surely be able to find examples of this on the internet since this is often used in modern web development due to the often unstable connection of smartphones.

you can try local storage to store the data and retrieve it after the browser re-opens Or cookies.

If you use mozilla you can hack the XUL codes and inject your scripts into it. Otherwise you must hack the browser template which supports js

Related

Using functions from my website in chrome console or firefox console?

I have a webpage up and running that has two js files with a bunch of functions. My HTML code loads these scripts as modules on startup. Problem is that i have a function called "showAdminTools()" and im afraid that this functions perhaps can be accessed through the chrome dev tools by non admins?
If the user isn't an admin, then don't send anything to their browser which should only be available to admins.
If the script is sensitive, then put it behind Authn/Authz and don't include it in a <script> if the user isn't an admin.
Yes everyone can access them with the console.
Actually im stupid, i already have server side code that prevents requests from client unless the user already is admin, so it does not matter if they can go into admin tools or not, any request from the admin tools page will be denied by server...
SORRY FOR WASTING TIME

JS: Load page content from web (if possible), fallback to local copy

I have an application I develop. It should show some stuff like help and legit stuff in a WebBrowser control. This works so far. I can use either a local .mht file or a url.
But I want to use both. So the content will be used online (if possible) or offline if the system has no internet connection.
Now I'm thinking about a pure JS solution, so the script tries to get the page online and displays it, or if it fails uses the local stored copy of it.
Any thoughts?
Any sort of AJAX request you make in any library will let you give an error handler. If an error happens, that's when you load the local copy.

Persistent Local JavaScript - Chrome Debugger

I remember several years ago that I was able to save a remote JavaScript file from a website onto my local in Chrome Debugger, make a few code adjustments, and refresh the page so Chrome will be reading the local copy of the JS file. I am wondering if this feature is still available, and if so how am I able to use it?
I know that I can add breakpoints to achieve something similar. I have followed a few guides, but none of them was able to achieve what I want:
https://developers.google.com/web/tools/setup/setup-workflow?hl=en
https://www.sitepoint.com/edit-source-files-in-chrome/
It looks as though you can only achieve this when you are using a local server. According to the Stage persisted changes section of the API:
If you are mapping files from a remote server instead of a local server, when you refresh the page, Chrome reloads the page from the remote server. Your changes still persist to disk and are reapplied if you continue editing in Workspaces.
It seems you could achieve what you want if you use Fiddler AutoResponder:
Fiddler's AutoResponder tab allows you to return files from your local disk instead of transmitting the request to the server.

Direct Print RDLC report on client PC in ASP.NET

I have read many articles and answers here regarding this but nothing can solve my issue. That's why I am asking this question again.
I develop a Invoice App in Asp.net. I can't print invoice directly on client PC. It always ask printer preview that irritate client. I have successfully develop a code for directly printing but it only execute on local host only.
Please help me and suggest me what to do as soon as possible.
In Javascript or ASP.NET or something else that can help me.
We use SSRS and generate the report in pdf format on the server. Sending it to the client, we send it with a mime-type:application/x-xyz-printpdf - you also have to set the content-disposition: with filename and I can't recall if inline or attachment value, so that the browser will behave and not simply download and save the file, but will kick off the associated program
the client has a slightly modified version of SumatraPDF, which is associated with application/x-xyz-printpdf in the registry (windows clients only - there's ways to do this in other OS's but all our clients run Windows, so we've never bothered)
This modified sumatraPDF never displays the document, all it does is display a print dialog with the previously selected printer for the report selected. This is so, invoices will default to one printer, other reports to a different printer, it's more of a convenience (and emulates our old non-web-based application)
I am in the process of rewriting the report printing subsystem, using a substantially modified version of PDFjs and blobs, but that's in early development so I can't tell you anything about that, except that it looks like it'll work well, without the need for an external program.

Saving data to a local file using only JavaScript

The set-up in question:
I have a stand alone, offline, kiosk mode instance of Chrome running on a Windows machine. I have full access to the system and any admin rights. I can start Chrome with any flags set or unset.
The task:
I have been asked to create a log file which tracks user activity within the offline app I am coding. It's a simple form of analytics which will append each event to the end of the file separated with a comma. The file will then be sent to a server once a day via a scheduled task. (None of this is my idea so please don't troll me)
Ruled out:
Any server side code - I have lobbied for Node, PHP etc but as this will be distributed to many different installations so we cannot guarantee this will be installed.
Flash/ActiveX/Java - ideally would like to avoid this (even though these will be installed by default)
Possible solutions:
File API - I have looked at this but AFAIK if opens dialogue boxes to save the data to each file and this needs to happen in the background.
Security - I have read in other SO Questions that this can be achieved if the security settings are reduced but no-one goes on to explain which ones. Is there a simple flag which allows it?
How to enable local file system read write access from Google chrome? - similar question!
Ideal result: (something akin to PHP)
$file = 'log.txt';
$current = file_get_contents($file);
$current .= ",clicked:link";
file_put_contents($file, $current);
Possible ideal side result: proving this isn't possible and forcing PHP/Node/Java to be used ;)
In reply to those suggesting local storage : I'm not storing unique key/value pairs and that is very much like setting a cookie. Similarily there are file size limits.
To those suggesting web SQL such as SQLite in chrome - there are file size limits if it's not a chrome extension. The only way I see that working is if I were to find the location of the file in the windows directory (C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default\databases) and upload that from the schedules task. Perfectly feasible but it is not a desirable answer.
You could use HTML5?
http://diveintohtml5.info/storage.html
var foo = localStorage.getItem("bar");
// ...
localStorage.setItem("bar", foo);
You can use the Chrome Apps File API, you will need to grant access to the file via a user action once, but after that you can get access the file again by using restoreEntry
You can use localStorage to save offline data. It's impossible to access other files using Javascript since it's a violation of the sandbox.
From http://en.wikipedia.org/wiki/JavaScript#Security:
JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using two restrictions. First, scripts run in a sandbox in which they can only perform web-related actions, not general-purpose programming tasks like creating files.
You may want to look into Local Storage which is part of the HTML5 spec.
This will only be supported in modern browsers though.
If you need to use older browsers then may still be able to achieve what you're after using dojox.storage
Use HTML5 features like Web Storage or Web SQL database to store your logs.
Whenever needed read logs from the client side storage and send it back to the server & delete the client storage.
Refer http://www.html5rocks.com/en/features/storage.

Categories

Resources