WebView jump to anchor using loadDataWithBaseUrl

后端 未结 5 1341
名媛妹妹
名媛妹妹 2021-01-02 10:25

My Android app uses a WebView to display a bunch of HTML code that I generate \'on the fly\'. The HTML code is loaded using the following code:



        
5条回答
  •  北海茫月
    2021-01-02 11:06

    First of all, you don't need to use javascript. If you loaded content with

    webContents.loadDataWithBaseURL("some://dummy/url",...);
    

    you can simply scroll to anchor with

    webContents.loadUrl("some://dummy/url#anchor");
    

    Secondly, doing that on onPageFinished without additional control results in never ending loop! When loadUrl finishes onPageFinished get's called again and again.

提交回复
热议问题