1

I have 2 html pages and I want to use a "webview" to load them in an android application. This is their code: page1.html:

<html>
 <body>
 <script>
 localStorage.setItem('token',123);
 alert("page1 "+localStorage.getItem('token'));
 window.location.replace("page2.html");
 </script>
 </body>
 </html>

page2.html

<html>
 <body>
 <script>
  alert("page2 "+localStorage.getItem('token'));
 </script>
 </body>
 </html>

This should show an alert in page 1 and then another in page 2 and both of them should show "123" BUT:

on the second page localStorage.getItem return null.

I've tested this app on 2 devices: on LG Prada with Android 4.3 (cyanogenmod) it doesn't work. on LG Nexus with Android 4.4.2 and it works!!

This is my java code:

WebView webView = (WebView)findViewById(R.id.webviewer);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);


webView.setWebChromeClient(new WebChromeClient());

webView.clearHistory();
webView.clearFormData();
webView.clearCache(true);


webView.loadUrl("file:///android_asset/www/page1.html");

My question: why does it work on one device but not the other? what did I do wrong? Is there a way to pass data from 2 html document that is supported in previous version of android?

FSFisGOOD
  • 193
  • 1
  • 11
  • I have a similar issue, not related to different versions but device manufacturers. http://stackoverflow.com/questions/26105245/localstorage-html5-feature-not-working-in-webview-on-samsung-android-device – Mathias Conradt Sep 29 '14 at 17:10

0 Answers0