是否可以将 Android WebView 屏蔽为 iPhone“应用程序模式”? Safari 浏览器?
所以我知道有些网站通过检查 window.navigator.standalone 来检查它是否被 iPhone 应用程序模式浏览器命中。是否可以将 Android webview 屏蔽为 iPhone 应用程序模式浏览器?
我已经尝试过以下代码,但它似乎对我正在尝试工作的网站不起作用。
WebView webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
/* WebViewClient must be set BEFORE calling loadUrl! */
webView.setWebViewClient(new WebViewClient() {
@Override public void onPageStarted(WebView view, String url, Bitmap favicon) {
}
// intercept page finished event
@Override public void onPageFinished(WebView view, String url) {
if(DEBUG) Log.v(TAG, "done");
view.loadUrl("javascript:javascript:(function() { " +
"window.navigator.standalone=1;" +
"})()");
}
// intercept clicked link event--load in this webview
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadUrl("<website>");
So I know some websites check to see if it's being hit by an iPhone App Mode browser by checking window.navigator.standalone. Is it possible to mask an Android webview as an iPhone App Mode browser?
I've tried the following code, but it doesn't seem to do the trick against the site I'm trying to get to work.
WebView webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
/* WebViewClient must be set BEFORE calling loadUrl! */
webView.setWebViewClient(new WebViewClient() {
@Override public void onPageStarted(WebView view, String url, Bitmap favicon) {
}
// intercept page finished event
@Override public void onPageFinished(WebView view, String url) {
if(DEBUG) Log.v(TAG, "done");
view.loadUrl("javascript:javascript:(function() { " +
"window.navigator.standalone=1;" +
"})()");
}
// intercept clicked link event--load in this webview
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.loadUrl("<website>");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WebSettings.setUserAgentString() 可能就是您想要的。
将其设置为类似:
WebSettings.setUserAgentString() is probably what you want.
Set it to something like:
尝试使用 iPhone 模板图像绘制布局,并通过
setContentView(LAYOUT_ID)
在您的 webview 活动中使用该布局Try to draw a layout using the iPhone stencil images and use that layout with your webview activity by
setContentView(LAYOUT_ID)