Determine element of url from webview shouldOverRideUrlLoading

后端 未结 2 1951
醉酒成梦
醉酒成梦 2021-01-23 19:07

I am displaying a html in a custom activity with a webview. I am overriding

public boolean shouldOverrideUrlLoading(WebView view, String url) {

2条回答
  •  佛祖请我去吃肉
    2021-01-23 19:47

    There is a dirty hack:

    1. Bind some Java object so that it can be called from Javascript with WebView:

      addJavascriptInterface(javaObjectExposed, "JSname")
      
    2. Force execute javascript within an existing page by

      WebView.loadUrl("javascript:window.JSname.passData("some data");"); 
      

    Described here: http://lexandera.com/2009/01/extracting-html-from-a-webview/

    Note: this is a security risk - any JS code in this web page could access/call your binded Java object. Best to pass some one-time cookies to loadUrl() and pass them back your Java object to check that it's your code making the call.

提交回复
热议问题