Changing the hash of the Android web view without reloading the page

I have a custom webview setup that works very well, but I would like to be able to:

1, change the hash of the url without refreshing the webpage (it will lose the state of my js application)

2, call some js that are inside my webpage inside android. Unfortunately, I can’t change the JS on the site, so the user cannot write any js to be placed on the site, especially for work, the only element I control is the Android application.

Can anyone think of how to do this?

Thanks in advance.

M

+3
source share
3

# 2 JavaScript. , , loadUrl JavaScript:

mWebView.loadUrl("javascript:wave()");

: http://developer.android.com/resources/articles/using-webviews.html

+1

, , :

view.loadUrl("javascript:location.hash=\"#" +fragment+"\"");
+4

I know this question is old, but this is what works for me in Android 4.4:

String fragment = "#test"
mWebView.evaluateJavascript("location.hash=\"" + fragment + "\";", new ValueCallback<String>() {
     @Override
     public void onReceiveValue(String value) {
         // Yes, I like to log data :-)
         Log.d("MyApp", "onReceiveValue(value): " + value);
     }
});
0
source

Source: https://habr.com/ru/post/1744195/


All Articles