【发布时间】:2015-03-22 16:12:22
【问题描述】:
我正在尝试解决 javascript 和 Disqus 的问题,我必须实现我的 WebView,我所做的只是从 url 下载 html 以及一些字符串替换
html = html.replaceFirst("<div", "<div id=\"headerApp\"></div><div");
html = html.replace("<head>", "<head> <style>"+cssContent +"</style>");
html = html.replace("class='hidden-phone'"," ");
html = html.replace("class=\"btn-mobile-pager visible-phone\"","class=\"btn-mobile-pager hidden-phone\"");
然后调用
loadDataWithBaseURL("blarg://ignored", html, "text/html", "utf-8", "");
但是disqus cmets很奇怪,看起来像这样:
我相信这是某种 javascript 问题,这就是我所做的:
WebSettings settings = myWebView.getSettings();
settings.setSupportZoom(false);
settings.setBuiltInZoomControls(false);
settings.setLoadsImagesAutomatically(true);
myWebView.setWebChromeClient(new WebChromeClient());
myWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView viewx, String urlx) {
MyWebView myView = null;
if(viewx instanceof MyWebView) {
myView = (MyWebView) viewx;
if(urlx.contains("https://twitter") || urlx.contains("action=em_fb_edit"))
{
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlx));
startActivity(browserIntent);
myView.stopLoading();
return true;
}
else if (!urlx.startsWith("http://www.efficacemente")) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlx));
startActivity(browserIntent);
return false;
} else if (urlx.contains("@facebook")) {
//Fai l'intent a facebook se puoi
if (isAppInstalled("com.facebook.katana")) {
String uri = "fb://page/101189567644";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
return false;
} else {
String url = "http://www.facebook.com/101189567644";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
return false;
}
} else if (urlx.contains("@twitter")) {
if (isAppInstalled("com.twitter.android")) {
String uri = "twitter://user?screen_name=EfficaceMente";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
return false;
} else {
String url = "http://www.twitter.com/Efficacemente";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
return false;
}
} else if (urlx.contains("@bookclub")) {
if (isAppInstalled("com.facebook.katana")) {
String uri = "fb://page/256384041207653";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
return false;
} else {
String url = "http://www.facebook.com/256384041207653";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
return false;
}
} else {
myView.myLoad(urlx);
return true;
}
}
else
return false;
}
});
myWebView.clearCache(true);
myWebView.clearHistory();
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView 是我创建的 MyWebView 类的一个实例,我只需将 html 下载到 html 并使用 loadDataWithBaseURL 加载它
有什么提示吗?谢谢!
【问题讨论】:
标签: javascript android html webview android-webview