Android WebView Related

I have several html files that I saved in the resource folder. one of my html files:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> .outer{width:300px; height:460px; padding:10px;} </style> </head> <body> <div class="outer"> <h4 style="text-align:right; margin-bottom:30px; width:300px;"><a href="#0">HOME</a></h4> <h1>World Map -01</h1> <img src="world_map.png" width="300" alt="" /> <h4 style="text-align:right; margin-top:30px; width:300px;"><a href="#2">NEXT</a></h4> </div> </body> </html> 

There are 3 more html files, like this one. The first page will be loaded. here i want to get href and download the links manually by checking href.

My code is:

 public class WebvwActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); WebView web=(WebView) findViewById(R.id.web); web.getSettings().setJavaScriptEnabled(true); web.loadUrl("file:///android_asset/demo.html"); } } 

What I want to do to get the href value and load the links by checking the href value

Thank you in advance

+4
source share
2 answers

For this you can use WebView WebViewClient. There is a function shouldOverrideUrlLoading that can be used to determine the href value and can be executed accordingly.

0
source

Try one of these methods to start it in the usual way:

 <li><a href="testing2.html" data-transition="none" rel="external">testing2</a></li> 

and put the file test2.html in the www folder

0
source

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


All Articles