0

这是我用来提取网站源代码的代码,我需要提取其中的一部分,并将其显示在 android webview 中。

在这段代码中,我只是将源代码保存在一个名为“sourcecode”的字符串中,我想将此 html 代码加载到我的 web 视图中;它可以做到这一点,但它没有应用任何 css 或 java 脚本。

有没有办法应用它们?

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    WebView wb = (WebView) findViewById(R.id.webView1);
    final String mimetype = "text/html";
    final String encoding = "UTF-8";
    String html="<H2>Problme with loading Page</H2>";

            //here i used the method "getUrlSource()" that i wrote myself   
    String sourceCode ="";
    try {
        sourceCode = getUrlSource("http://www.nerkh.co");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        wb.loadDataWithBaseURL("", html, mimetype, encoding, "");
    }

    wb.loadData(sourceCode, mimetype, encoding);


}
4

1 回答 1

0

你是否为你的 webview 启用了 javascript

webview.getSettings().setJavaScriptEnabled(true);?

Css 和 javascript 应该只适用于缓存的网页。
您可能需要 Internet 连接才能加载引用的 css/js 文件。
我怀疑该方法可能有问题getUrlSource

于 2013-06-22T10:28:04.453 回答