Webview是不是表现得像个铬 [英] WebView Is not behaving like Chrome

查看:271
本文介绍了Webview是不是表现得像个铬的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网页视图中打开一个网址登录,这样用户可以轻松率我的客户酒店。

I'm trying to open a TripAdvisor URL in my web view, so the users can easily rate my client Hotel.

所以我所做的就是在手机中打开登录网站,Chrome应用中复制的URL,然后在Web视图使用loadURL方法使用它。

So what I did was to open the TripAdvisor web site in the Phone Chrome App copied the URL and then use it in the web view loadUrl method.

但好像Web视图正在除Chrome不同的一个电话,我的猜测是不是要告诉这是一个在Chrome浏览器的服务器。

But it seems like the Web View is making a call different than Chrome and my guess is that is not telling to the server that is a "Chrome Browser".

所以,如果我在Chrome直接在超链接在例如得到这个页面点击电子邮件中打开页面:

这正是我期待的行为。

但是,如果我调用相同的URL在我的Web视图我得到这个页面:

现在我只用这code,以保持它的清洁:

Right now I'm using just this code to keep it clean:

webview = (WebView) findViewById(R.id.webView);
webview.setWebChromeClient(new WebChromeClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(tValue);

但我都试过了这一切,但是没有一样能告诉登录的行为就像是一个Chrome的电话:

But i have tried all this, and nothing seems to tell to TripAdvisor to behave like it was a Chrome call:

webview = (WebView) findViewById(R.id.webView);
webview.setWebViewClient(new WebViewClient());
webview.setWebChromeClient(new WebChromeClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webview.clearCache(true);
webview.clearHistory();
webview.loadUrl(tValue); 

我做的完全一样在我的iOS应用程序和UIWebView的行为或告知给服务器相同的,因为它是在Safari中打了一个电话。

I'm doing exactly the same in my iOS app and the UIWebView behaves or tells to the server the same as it was a call made in Safari.

有没有办法改变一些页眉或有事要告诉我的Web视图是一个在Chrome浏览器的服务器?

Is there a way to change some header or something to tell the server that my web view is a "Chrome Browser"??

先谢谢了。

更新1:

由于多米尼克k的答案我尝试了所有的用户代理的他建议和仍然没有工作。

Thanks to the answer of Dominik K i tried all the user agents he suggested and still nothing work.

因此​​,发生在我来测试剂的两者的和实际上它们是不同的,但即使是使用一个是使用Chrome,没有令人满意的结果。

So it occurs to me to test the agent of both and in effect they are different, but even using the one that is using Chrome, there is no satisfying result.

我认为这是没有很好地回答这一个。

I think that there is no good answer to this one.

推荐答案

好吧,我已经做到了,

由于多米尼克k的答案和大量的测试,我发现一个不那么优雅的解决这个问题。

Thanks to the answer of Dominic K and a lot of testing I have found a not so elegant solution to this problem.

我们的目标是要查看发表评论,并率酷似iOS设备。

The goal was to view the "Leave a comment and rate" exactly like in an iOS device.

所以最终我已经改变了用户代理在Android的WebView到使用的iOS UIWebView中的人。

So at the end I have changed the user agent in the Android WebView to the one that use the iOS UIWebView.

在Android上的code是这样的:

The code in Android looks like this:

webview = (WebView) findViewById(R.id.webView);
webview.setWebChromeClient(new WebChromeClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setUserAgentString("Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.14 (KHTML, like Gecko) Mobile/12F70");
webview.loadUrl(tValue);

在这里,你有一些画面,结果拍摄:

Here you have some screen shoots with the result:

ANDROID:

的iOS

快乐编码的帮助表示感谢。

Happy coding and thanks for the help.

这篇关于Webview是不是表现得像个铬的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆