Javascript在我的WebView实现中工作不正常
我试图解决javascript和Disqs的一个问题,我必须实现我的WebView,我所做的只是从url下载html以及一些字符串替换Javascript在我的WebView实现中工作不正常,javascript,android,html,webview,android-webview,Javascript,Android,Html,Webview,Android Webview,我试图解决javascript和Disqs的一个问题,我必须实现我的WebView,我所做的只是从url下载html以及一些字符串替换 html = html.replaceFirst("<div", "<div id=\"headerApp\"></div><div"); html = html.replace("<head>", "<head>
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\"");
但是论文的评论很奇怪,看起来像这样:
我相信这是某种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加载它
有什么提示吗?谢谢 而不是blarg://ignored,在转换网页之前,请使用该网页的实际URL。您的方法意味着任何通过相对URL引用的东西都无法加载,例如图像、JavaScript、CSS等,因为WebView不知道这些东西从何处加载
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);