App inventor 2 en español
Cómo programar los teléfonos móviles con Android.
Curso de App inventor 2 en español - Juan Antonio Villalpando
-- Tutorial de iniciación de App Inventor 2 en español --
Volver al índice del tutorial
___________________________
170C.- Cookies con JavaScript.
p170C_Cookies_JS_v1.aia
- Vamos a leer cookies mediante JavaScript.
________________________________________________________________________________________
- Códigos.
cookie_set.htm |
<script>
// Example: cname_cvalue: "age=24"
cname_cvalue = window.AppInventor.getWebViewString(); // INPUT
document.cookie = cname_cvalue + ";expires=Sat, 18 Dec 2038 12:00:00 UTC;domain=localhost;path=/";
</script>
|
cookie_get.htm |
<script>
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
cname = window.AppInventor.getWebViewString(); // INPUT
AppInventor.setWebViewString(getCookie(cname)); // OUTPUT
</script>
|
_________________
- Diseño.
_________________
- Bloques.
______________________________________
2.- Con RunJavaScript.
p170C_Cookies_JS_v2.aia
_________________
- Bloques.
__________________________________
|