0

I load data from html to web view and there are link some where of my data that load in web view and i want when i click them there should be function call as complete action using. So i can load that link in other net browser.

Hitesh Matnani
  • 533
  • 2
  • 8
  • 26
  • paste some code you have tried yet. As far as I understand your question you should use `WebView webView = (WebView) view.findViewById(R.id.webView1); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webView.getSettings().setJavaScriptEnabled(true); webView.loadUrl(url);` – XtreemDeveloper Sep 24 '14 at 04:24
  • i am using this web1.loadData(htmldata,"text/html; charset=utf-8",null); as i have to load html data in web view and that is happening but the data i load like - read more go to google.com.... so i need when i click on google.com that is shown in my web view that open in my other web browser – Hitesh Matnani Sep 24 '14 at 04:47
  • so, you are not using any `url` to load into the `webview` ? – XtreemDeveloper Sep 24 '14 at 04:50
  • no how can i load a string in webView.loadUrl(url); so i am using web1.loadData(htmldata,"text/html; charset=utf-8",null); – Hitesh Matnani Sep 24 '14 at 04:54
  • you have your html file copy that file into your project's `Assets` folder and then load that file using `web1.loadUrl("file:///android_asset/yourHtmlFileName.html");` – XtreemDeveloper Sep 24 '14 at 05:02
  • It like this String htmldata = "d" here d is the string that content the value of pares data by json. now how can copy that to my assets folder. please help – Hitesh Matnani Sep 24 '14 at 05:15
  • you should take a look at this answer http://stackoverflow.com/a/4543485/3982085 – XtreemDeveloper Sep 24 '14 at 05:22
  • can you please help in how to copy the to assets folder – Hitesh Matnani Sep 24 '14 at 05:30

2 Answers2

0

Here is sample html for example:

<html>
<body>
    This is some string
</body>
</html>

Save this html file as "filename.html" on your desktop

Now copy that file and paste into your Assets folder

After that go to your Java code and write code:

web1.loadUrl("file:///android_asset/filename.html");

EDITED

Here is another way if you want dynamic value as content of your html see below

String d = "your dynamic string value";

String your_html = "<html><body>"+d+"</body></html>";

web1.loadData(your_html, "text/html", "UTF-8");
XtreemDeveloper
  • 1,132
  • 9
  • 14
  • thnxs it done. can you tell me if i want to do like this how can i String d = "This is some string" then in assets folder +d+ then in activity web1.loadUrl("file:///android_asset/filename.html"); – Hitesh Matnani Sep 24 '14 at 05:55
  • yha i am doing this but id and case if my string d = "read more go to www.google.com" and when i do web1.loadData(your_html, "text/html", "UTF-8"); its done but when i click on www.google.com i need it open in other net browser not in my application – Hitesh Matnani Sep 24 '14 at 06:06
  • I edited again my answer see now use `web1.loadData(your_html, "text/html", "UTF-8");` – XtreemDeveloper Sep 24 '14 at 06:08
  • @HiteshMatnani now check my edit its working on my side. – XtreemDeveloper Sep 24 '14 at 06:09
  • `web1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); web1.getSettings().setJavaScriptEnabled(true);` add these two statements before `web1.loadData` – XtreemDeveloper Sep 24 '14 at 06:12
  • yha checked thanks for it @XtreemDeveloper but i need is that - d = "read more go to www.google.com" and when i do web1.loadData(your_html, "text/html", "UTF-8"); its done but when i click on www.google.com i need it open in other net browser not in my application – Hitesh Matnani Sep 24 '14 at 06:12
0

Try this one:

myWebView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return false;
    }
});

Ref. from: Link should be open in same web view in Android

Keep Googling :)

Community
  • 1
  • 1
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437