Cookies javascript in webview smartphones!

Asked

Viewed 339 times

1

I would like to know if someone knows how to use or can inform if you take Cookies directly from the webview of the smartphone device..

I know they are functions of a browser, but I am making an APP that it needs to save temporarily or permanently, until it is changed, the user login, and the app is entirely in HTML, ie it is not quite an application of the type JAVA, but HTML5, CSS3 and JAVASCRIPT.

inserir a descrição da imagem aqui

And so that the user does not have to log in every time they open the app would like to save this login data in some way on the device, be it cookies, or creating a txt type file with the information...

1 answer

1


The most reliable solution is localStorage. The localStorage is an object where you can save strings to the keys of that object and that has no time limit.

For example:

localStorage.appUser = 'Pedro';

and later you can use localStorage.appUser to know what value is saved.

In Avascript you cannot save files. You can always send to the server but if you want to save to the computer/browser where the user is then localStorage is what I advise you to use.

Example: http://jsfiddle.net/y6Lpu8m1/

  • But say the user closes the app or restarts the mobile app, this function will keep the value?

  • @Stone tested the jsFiddle I made. It has a field primeiroLogin and another ultimoLogin. Notice how the first one is always the same and the second one is being updated.

  • can inform why this command is not working?? $(document).ready(function(){
 if(localStorage.userlogin !== "undefined") {
 alert(localStorage.userlogin);
 };
});

  • the code in general... http://jsfiddle.net/pedroquezado/qafk7j67/ should give a Alert() returning the localStorage.userlogin only if it had been filled in, in the case other than Undefined, but even then it gives an Alert.. FAILL! ;(

  • 1

    @Stoner uses typeof http://jsfiddle.net/y6Lpu8m1/1/

  • when the user leaves? I can clean the localStorage with localStorage.clear();?

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.