using browser local storage in phonegap application - javascript

I'm creating a mobile application (For IOS, Android) and I first develop it in my browser. I need to use the local storage. I understand that local storage is working for a specific domain (A bit like cookies). The thing is that now when I'm working on the development server I have a domain and local storage is working correctly. What i'm a bit worried is that when I move to Phonegap and run the files locally I might not have access to local storage as there is no domain (a bit like not having cookies when you develop on an IP instead of a domain).
I know that phonegap has it's own storage but I rather not use it now as it's web sql based which is depricated as far as I understood by researching).
So, if the HTML files are local in the Phonegap webview application (not opened from a remote server, but stored locally) can I still use the local storage?
Thanks.

LocalStorage works just fine in a PhoneGap/Cordova app.

Related

Communicating with PHP from an android app without internet?

I have made a web page and i am running it on a local host using the xampp server. In this web page I have a canvas that draws a line between two point. I read these points from a locally available csv file that I have generated. I would like to make an android application, where there is a provision to enter two numbers. I want this android application to make a csv file and save it on my computer so that I can access this file using my javascript.
Note: can I pass these values via an usb connected between the mobile and computer so that I can make a csv file locally in my computer? I want all of this to happen without the requirement of internet connection.
PS: I am newbie to android. If the above is possible, then please brief on how to approach this problem.
If you have a XAMP server all you need to do is connect the android device to the same network/router. There you can talk via HTTP methods to the apache server. You will just need to provide the ip address to the android app.
In the router you can set a static ip address for the mac address of your computer, so every time it connects to the router it always get the same IP and you dont need to input it again on the android app.

Get userID of current windows user in my website via JavaScript

I have a feature in my upcoming web project where I will have to get the UserID/Email ID of the user currently logged in to the machine/PC. Target OS is Windows 10 and logins to the machines are done via Smart Card only. User Data is stored inside MS-AD.
This UserID will be used passed further for Authorization and load the app in browser. The target browser is IE and Chrome.
Is there a way i can fetch the EmailID/UserID of the User logged in via Smart Card to system in Javascript?
ADDITIONAL INFO: The website is setup in private environment. There is no public URL to access the webapp from outside Intranet. The client and backend code is hosted inside VM in Cloud. In nutshell, the is all sitting in private environment in Azure.
Thanks!
Not with JavaScript. JavaScript is run inside the browser container, and more specifically run inside your current webview. Letting JavaScript get access to settings and data on the local machine be a nightmare if phishing, malware and virus sites.
If you know which computers will run your website you could create an application with a server that's running idle on the machine, much like how Spotify's client is doing (the windows client can take commands from the webpage).
The application/server could then try to get the EmailID/UserID from the computer, and then having the server running on some specific port, your JavaScript could then use AJAX-requests to communicate with the local machine from the browser.
I could get the Windows Logged in user using the ActiveX script in IE.
var WinNetwork = new ActiveXObject("WScript.Network");
alert(WinNetwork.UserName)
Will this be a good approach to solve this issue?

Web app with "off-line" mode?

I am designing an application that must work regardless of whether or not there is an Internet connection. Most of the time (90%), there will be an Internet connection, in which case it will behave like normal. However some of the time the user will not have Internet, in which case I would like to store all their in-session data to the file system, and whenever an Internet connection becomes available again, allow the user to synchronize the saved data from there disk with the backend server.
My thinking was to have a single-page web app that compiles down to a JS file and in "online mode" gets served up from a web server. But in "offline mode", the user will have to have the JS file saved locally to their machine, and then open it in a browser. The app could auto-detect what mode it is in and either save data to the server (via AJAX) in online mode, or save the data to HTML5 local storage in offline mode.
Is this feasible, or is my total approach incorrect?
The only caveats I can see with it are:
Limited to browsers with HTML5 Local Storage capabilities, but I'm fine with that
Limited to the size of the HTML 5 Local Storage available on the machine
Any other thoughts?

Is localStorage safe? Can I access it from another app?

I am making a jQuery Mobile and PhoneGap app.
I am about to save some data to local storage. I am wondering if it is safe on mobile browsers (Android, iOS and windows). On PC I am able to check the values in FireBug. Is it possible somehow on mobile devices? Can I access in app A data specified by app B?
Thanks for help.
At least in iOS, if it's a phonegap app the localStorage is only accesible from the app.
To check values while you are developing, you can try debug phonegap.(only works on webkit browsers). If you put a name there, it creates a script tag to include in your index. If you include that script tag in your index and execute the app you can see a remote web inspector for your app.

Where are cookies saved for a local HTML file?

I created an HTML file on my desktop and added some JavaScript to set and clear cookies.
Now my question is, will the cookie be saved in my browser? Can I read it back?
if Yes,
For which domain will it be saved?
How can I see it in Google Chrome? (HTML run on Chrome)
Unfortunately some browsers including Google Chrome do not store cookies from local web pages:
Why does Chrome ignore local jQuery cookies?
Firefox has great developer plugins for cookie management, which report their domains, access paths and expiry:
https://addons.mozilla.org/en-US/firefox/addon/view-cookies/
https://addons.mozilla.org/en-US/firefox/addon/firecookie/ (Personal Favourite - Requires FireBug)
For local development purposes you can setup a development domain like "localhost" or "myfakedomain.com" and run your files on a local server.
Search:
Editing Hosts File [operating system]
Setup Local server on [operating system] (I use xampp)
If you're running the 'site' on a local webserver then it should be stored in your browser under 'localhost'. If however you're just opening a static HTML file Chrome will not store the cookie.
In Chrome you can use the Chrome Developer Tools and look under the 'Resources' tab.

Categories

Resources