开发者

page not available when opening link in webview

I take the response from an HTTP connection in the form of string and show that to webview like this:

WebView engine = (WebView)findViewById(R.id.webview);
engine.loadData(endResult, "text/html", "UTF-8");  /*endresult is string*/ 

I actually get a response that contains the google page (google search result direct from google.com).

The loadData method works well i.e it shows the web page but when I click on one of the links on that page it shows "page not available" and said that "xyz link might be temporarily down or it may have moved to permanently to a 开发者_运维问答new web address".

this happens for all links accept the first present link on that page. i.e it shows correct page from first link on that page but fails for others..


I noticed that OSes prior to 2.3 failed to follow links if setHorizontalScrollBarEnabled and setVerticalScrollBarEnabled are set to false.


try to use loadDataWithBaseURL of the WebView class


I would avoid using engine.loadData - it seems to cause all sorts of crazy problems.

Use engine.loadDataWithBaseURL instead, and pass the base URL of where the content exists. I would think that the content you are loading is using relative paths in it's HTML so it's looking inside your app resources. By specifying the base URL you get around this problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜