We currently have an Cordova application that needs to start an external browser with a POST.
We have it coded to use the inAppBrowser plugin to start a browser that is embedded within the app.
I don't like using the internal browser because I will be blamed for any bugs in the webpage that render in the default browser and don't work in the inAppBrowser.
How can we start the default browser with a POST request?
Once the browser starts we do NOT need to have a back button in the browser that will take the user back to our app.
We are only worried about iOS and Android. We can use different solutions on each of those platforms.
I have googled but there is so much conflicting information; there will be a response that it works, then another person replies that it does not. There also caveats to getting it to work; for instance, it seems that one can get the URL to open in the default browser, but it also leaves the page open in the in-app-browser as well. This would be confusing for the end user.
[EDIT] I have created an upwork.com project to pay someone to create a cordova plugin specific for starting the external browser with a POST request. Feel free to comment on any anticipated problems with doing that.
[EDIT] Here are the steps I used to test on iOS:
You can open a browser outside of the app with inAppBrowser by specifying the target eg.;
var linkTarget = "_blank" ; ( was using for desktop ; had coded target as _system for Android. Apologies.)
[EDITED]
<a href="#" onclick="window.open(encodeURI('https://openclipart.org/'),"_system")">openclipart.org</a>;
This doesn't open web page in the app - opens in system browser.
If the browser defaults have been cleared in the device settings app manager page this link will prompt the user for their choice of browser ( I'm assuming it otherwise uses the previously set default though you might want to double check particularly if you're using crosswalk )
There are other target options but seem to recall _system
not working as expected - give it a try if _blank doesn't work
I don't think there's any straight forward way to launch a browser doing a post even if you had a special plugin ;
Looks like using a dataUrl might allow you to open browser doing a post - if so prob the cleanest approach. ( see link in Wu's answer below ) [EDIT] looks like won't work on Windows mobile platforms though; see caniuse dataURIs .
Alternatively, you might try a separate html file as part of your app files - load it into a new browser as above (except "file://.." )and have it run some startup javascript (maybe using a querystring for control) to do the post eg. via a jquery ajax call. There will be security issues with this approach - the file will have to be somewhere the browser has access to ( can have app copy it there from internal www folder - need read/write permissions ) . Not sure if there will be CORS issues etc. I'd definitely look into the dataUrl first if windows not a consideration.
Looks like the "_blank" can not open url in external browser on iOS. I tried by this:
1) Install inappbrowser plugin.
2) call window.open(encodeURI(' https://openclipart.org/ '), "_blank"); when button pressed.
The url open in app, not external browser.
Update:
Use "_system" will open url in Safari on iOS, to open url :
1) Install inappbrowser plugin.
2) call cordova.InAppBrowser.open(encodeURI(' https://openclipart.org/ '), "_system");
Unfortunately this way only work to send get request. Some people suggest submit post form on loadstop event like this: Cordova InAppBrowser post form to url
The method worked when target is "_blank", when target is "_system", because open url in browser not app windows, the loadstop event will not be fired.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.