我有以下 webview 客户端,当我们查看 URL 中不包含单词 google 的页面时,它将用户代理设置为桌面浏览器。(也做其他事情,但一切正常)。
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.contains("google")) {
String newUA= "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";
webView.getSettings().setUserAgentString(newUA);
view.loadUrl(url);
}else {
webView.getSettings().setUserAgentString(null);
view.loadUrl(url);
}
return true;
}
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
super.onPageStarted(view, url, favicon);
progressBar.setVisibility(View.VISIBLE);
}
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
String page = webView.getUrl();
if (!(page.contains("google"))){
grabit.setVisibility(View.VISIBLE);
}else{
grabit.setVisibility(View.GONE);
}
webView.loadUrl("javascript: function loadScript(scriptURL) { var scriptElem = document.createElement('SCRIPT'); scriptElem.setAttribute('language', 'JavaScript'); scriptElem.setAttribute('src', scriptURL); document.body.appendChild(scriptElem);} loadScript('"+CFG.Bookmarklet+"');");
progressBar.setVisibility(View.INVISIBLE);
if (webView.canGoBack()){
left.setImageResource(R.drawable.ic_arrowleft);
}else{
left.setImageResource(R.drawable.ic_arrowleft_gray);
}
if (webView.canGoForward()){
right.setImageResource(R.drawable.ic_arrowright);
}else{
right.setImageResource(R.drawable.ic_arrowright_gray);
}
}
});
这个问题是,虽然在某些站点上它可以完美地工作,但在其他站点上却不能正常工作,而在某些站点上它似乎只是更改了视口。几个例子是:
> Argos - shows mobile
> Tesco - shows mobile but view port has changed
> Amazon - works
> John Lewis - shows mobile but view port has changes
> Play.com - works
那么我有什么遗漏吗?它不工作的网站的另一种方式是检查浏览器以决定显示什么?
Chrome 中的“显示桌面版本”似乎适用于这些网站。所以,chrome 可能会做其他事情吗?
谢谢