Reputation: 461
I'm trying to open a payment page with cordova InAppBrowser and i want to open that page in system browser on mobile devices. I'm also try the _blank param but _blank just open that page in the same window to app. And i also want to Send Post Request over Cordova InAppBrowser. this is my code:
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"
);
There is no action from this with _system param, and _blank just open the page in the same window to app. What should i do for open the payment page in system browser of device?
Upvotes: 8
Views: 1700
Reputation: 461
Finally I have found the solution in this branch of original InAppBrowser repository.
Anyone who has the same problem take a look at openExternal
function of this branch. It allows data be opened like an external link.
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();
}
}
After using the above function, everything is going right.
Upvotes: 4
Reputation: 4295
I have found that you have two problems (if there are more, explain them, so that I will update the answer):
How to post data to an inappbrowser with _system config.
And how to return from opened page, to the opener application.
Upvotes: 1