omi*_*ahi 7 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"
);
Run Code Online (Sandbox Code Playgroud)
_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();
}
}
Run Code Online (Sandbox Code Playgroud)
使用上述功能后,一切正常。
| 归档时间: |
|
| 查看次数: |
354 次 |
| 最近记录: |