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?
function openBrowser() { var url = 'https://cordova.apache.org'; var target = '_blank'; var options = "location = yes" var ref = cordova. InAppBrowser. open(url, target, options); ref. addEventListener('loadstart', loadstartCallback); ref.
you can hide the toolbar using the 'toolbar' option. you just need to set location to no and it'll hide the URL bar.
The InAppBrowser is a web browser view that displays when calling [window. open](window. open. html)() , or when opening a link formed as <a target="_blank"> .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With