javascript - cordova InAppBrowser 不适用于 _system 参数
问题描述
我正在尝试使用 cordova InAppBrowser 打开支付页面,并且我想在移动设备的系统浏览器中打开该页面。我也在尝试 _blank 参数,但 _blank 只是在同一窗口中打开该页面以应用。而且我还想通过 Cordova InAppBrowser 发送发布请求。这是我的代码:
var redirect = 'https://SomeRef';
var pageContent = '<form id="FormID" action="https://SomeOtherRefs" method="post">' +
'<input type="hidden" name="RedirectURL" value="' + redirect + '">' +
'<input type="hidden" name="Token" value="' + dataVar + '">' +
'</form> <script type="text/javascript">document.getElementById("FormID").submit();</script>';
var pageContentUrl = 'data:text/html;base64,' + btoa(pageContent);
var browserRef = cordova.InAppBrowser.open(
pageContentUrl,
"_system",
"hidden=no,location=no,clearsessioncache=yes,clearcache=yes"
);
_system 参数没有任何操作,_blank 只是在同一个窗口中打开页面到应用程序。如何在设备的系统浏览器中打开支付页面?
解决方案
最后,我在原始 InAppBrowser 存储库的这个分支中找到了解决方案。
任何有同样问题的人都可以看看openExternal
这个分支的功能。它允许像外部链接一样打开数据。
public String openExternal(String url) {
try {
// Omitting the MIME type for file: URLs causes "No Activity found to handle Intent".
// Adding the MIME type to http: URLs causes them to not be handled by the downloader.
Uri uri = Uri.parse(url);
String scheme = uri.getScheme();
Intent intent = "data".equals(scheme)
? Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_BROWSER)
: new Intent(Intent.ACTION_VIEW);
if ("file".equals(scheme)) {
intent.setDataAndType(uri, webView.getResourceApi().getMimeType(uri));
} else {
intent.setData(uri);
}
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
this.cordova.getActivity().startActivity(intent);
return "";
// not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
} catch (java.lang.RuntimeException e) {
LOG.d(LOG_TAG, "InAppBrowser: Error loading url " + url + ":" + e.toString());
return e.toString();
}
}
使用上述功能后,一切正常。
推荐阅读
- rust - 如何将编译时未知数量的迭代器压缩在一起?
- android - Android OnItemClick 无法将加载的 SQL 数据库加载到列表视图中
- python - 尝试编写一个显示在我桌面上的小日历程序
- python - 使用 Python 将表的行单元格替换为另一个表的行单元格
- python-3.x - scipy树状图中的倒置分支
- ios - 启动关系上的CoreData批量同步不保存
- javascript - 在javascript中获得反正弦的任何方法
- java - 如何在firestore中设置和覆盖整个arraylist
- c++ - 在 C++ 中声明指向对象的指针实际上意味着什么?
- python - 在一列中对另一列中共享相同值的值进行分组(熊猫:groupby.apply/multi-index)