简体   繁体   English

我如何从inappbrowser cordova请求一个桌面站点

[英]how can I request a desktop site from inappbrowser cordova

I am requesting a website using cordova inappbrowser 我正在请求使用cordova inappbrowser的网站

http://bugdevstudios.com/pixi/ http://bugdevstudios.com/pixi/

This website works correctly if we load it via desktop but not from mobile. 如果我们通过桌面而不是通过手机加载此网站,则该网站可以正常运行。 Do you have any idea what might be the issue? 您知道可能是什么问题吗? You can view the live website as well. 您也可以查看实时网站。 When I load it from mobile using "Request Desktop Website" in chrome or firefox (mobile) it works. 当我在Chrome或firefox(移动设备)中使用“请求桌面网站”从移动设备加载它时,它可以工作。

Inappbrowser doesn't support user-agent out of the box. Inappbrowser不支持用户代理。 Using a simple hack we may force inappbrowser to use cordova webview's user-agent-string. 使用简单的技巧,我们可以强制inappbrowser使用cordova webview的user-agent-string。

Open your InAppBrowser.java and edit the run method. 打开InAppBrowser.java并编辑run方法。

WebSettings settings = inAppWebView.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setBuiltInZoomControls(true);              
settings.setPluginState(android.webkit.WebSettings.PluginState.ON);             
settings.setUserAgentString(thatWebView.getSettings().getUserAgentString()); // magic line

Find more about "The Hack" here 在此处找到有关“ The Hack”的更多信息

Now to set cordova user agent string. 现在设置cordova用户代理字符串。 we will use a plugin cordova-useragent List of user agent string can be found here 我们将使用插件cordova-useragent用户代理字符串列表可在此处找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM