javascript - Android - save value on LocalStorage before WebView.loadUrl() -
before load url on webview want set value inside browser localstorage.
till way did managed set value after page loaded. how can set value:
browser.setwebviewclient(new webviewclient() { @override public void onpagefinished(webview view, string url) { loadurl("javascript: localstorage.set('namespace', 'key', 'value');"); } }
i did try override method onpagestarted()
, value not stored.
how can set key/value before call browser.loadurl()
? url/page depends on value, need set value before load page.
what can set redirect javascript
actual url , load javascript plus redirect using webview.loaddata()
.
string injection = "<html><head><script type='javascript'>localstorage.set('namespace', 'key', 'value');window.location.replace('your_url_here');</script></head><body></body></html>"; webview.loaddata(injection, "text/html", null);
be aware though might need save file first before works: see how load javascript redirect android webview?
Comments
Post a Comment