0

I am loading a webpage into a webview from the database with the loadDataWithBaseURL() function and am trying to subsequently jump to an Anchor point. When I place a button just below the webview that uses the loadUrl()-function, it jumps to the Anchor point just fine. But if I place the loadUrl() after the loadDataWithBaseURL() it says page not found.

webview.loadDataWithBaseURL("app:myhtml", data, "text/html", "UTF-8", null); webview.loadUrl("app:myhtml#tips"); 

I assumed it was because the load had not completed, and thus it couldn't find the Anchor, but I tried a loop to wait for it to getProgress() to equal 100, and have verified it's reaching 100 before that command executes, but it still won't find the page unless it's associated with the button click.

Any Ideas out there on how I can load a page from the database and then jump to an anchor point at the same time. I'm working with the Android 2.1 SDK.


Thanks to your help I got it to load directly to my anchor by adding this little bit of code. However I can't scroll around on the page, it starts to move and then snaps back. I suspect because it is reloading the page to that anchor each time. I'm fairly new to Android, and Java even, so this may be the wrong implementation of your suggestion, but I'd certainly appreciate a little more direction. Here is the code I used:

webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(webview, "app://data"); webview.loadUrl("app://data#tips"); } }); 

It seems this is making an infinite loop.

1

2 Answers 2

1

Try using valid URL as a base URL in loadDataWithBaseURL(), such as app://myhtml.

Also, to make sure the data was loaded implement WebViewCLient.onPageFinished().

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to your help I got it to load directly to my anchor by adding this little bit of code. However I can't scroll around on the page, I suspect because it is reloading the page to that anchor each time. I'm fairly new to Android, and Java even, so this may be the wrong implementation of your suggestion, but I'd certainly appreciate a little more direction. webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(webview, "app://data"); webview.loadUrl("app://data#tips");} });
0

It was getting in an infinite onPageFinished loop before. It had nothing to do with me scrolling, it was just continuously loading the same page. This code allows it to load without without getting stuck in a loop.

webview.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { if(url.contains("#") != true){ webview.loadUrl("app://data#tips"); } } }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.