javascript - cordova InAppBrowser 不适用于 _system 参数

标签 javascript android cordova inappbrowser

我正在尝试使用 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 参数没有任何 Action ,_blank 只是在同一个窗口中打开页面到应用程序。如何在设备的系统浏览器中打开支付页面?

最佳答案

最后我在这个 branch 中找到了解决方案原始 InAppBrowser 存储库。

有同样问题的 friend 看看这个分支的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();
    }
}

使用上面的函数后,一切正常。

关于javascript - cordova InAppBrowser 不适用于 _system 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53790584/

相关文章:

javascript - div类更改时更改背景颜色?

android - Twitter Bootstrap 导航栏下拉菜单不起作用

ios - PhoneGap/Cordova pushplugin iOs 注册回调未触发

javascript - 将对象数组分组到嵌套映射中

javascript - 为什么 page-mod 模块中的 onAttach 没有在 Firefox add-on sdk 中执行?

javascript - Bootstrap 表 : sort by date field

Android - 在自定义 EditText 上捕获退格(删除)按钮

android - 如何在android smack 4.2.0-beta1中使用MucEnterConfiguration?

android - 使用 Intent URI 启动我的应用程序

android - 将 Phonegap Android 从 2.5 升级到 2.6 和 2.7 步骤