[英]Start External Browser from Cordova
We currently have an Cordova application that needs to start an external browser with a POST. 我们目前有一个Cordova应用程序需要通过POST启动外部浏览器。
We have it coded to use the inAppBrowser plugin to start a browser that is embedded within the app. 我们将其编码为使用inAppBrowser插件来启动嵌入在应用程序中的浏览器。
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. 我不喜欢使用内部浏览器,因为我会被指责在默认浏览器中呈现的网页中的任何错误并且在inAppBrowser中不起作用。
How can we start the default browser with a POST request? 我们如何使用POST请求启动默认浏览器?
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. 我们只担心iOS和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. 例如,似乎可以在默认浏览器中打开URL,但它也会在应用程序内浏览器中打开页面。 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. [编辑]我创建了一个upwork.com项目来支付某人创建一个cordova插件,专门用于通过POST请求启动外部浏览器。 Feel free to comment on any anticipated problems with doing that. 随意评论任何预期的问题。
[EDIT] Here are the steps I used to test on iOS: [编辑]以下是我在iOS上测试的步骤:
You can open a browser outside of the app with inAppBrowser by specifying the target eg.; 您可以使用inAppBrowser在应用程序外部打开浏览器,方法是指定目标,例如。
var linkTarget = "_blank" ; var linkTarget =“_ blank”; ( was using for desktop ; had coded target as _system for Android. Apologies.) (用于桌面;已将目标编码为Android的_system。道歉。)
[EDITED] [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还有其他目标选项,但似乎回想起 _system
没有按预期工作 - 如果_blank不起作用,请尝试一下
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. 看起来像使用dataUrl可能允许你打开浏览器做一个帖子 - 如果是这样的话,最干净的方法。 ( see link in Wu's answer below ) [EDIT] looks like won't work on Windows mobile platforms though; (请参阅以下吴的答案中的链接)[编辑]看起来不适用于Windows移动平台; see caniuse dataURIs . 请参阅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. 或者,您可以尝试将单独的html文件作为应用程序文件的一部分 - 将其加载到上面的新浏览器中(“file:// ..”除外)并让它运行一些启动javascript(可能使用查询字符串进行控制)做这个帖子,例如。 via a jquery ajax call. 通过jquery ajax调用。 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 ) . 这种方法会出现安全问题 - 文件必须是浏览器可以访问的地方(可以将应用程序从内部www文件夹复制到那里 - 需要读/写权限)。 Not sure if there will be CORS issues etc. I'd definitely look into the dataUrl first if windows not a consideration. 不确定是否会有CORS问题等。如果不考虑windows,我肯定会先查看dataUrl。
Looks like the "_blank" can not open url in external browser on iOS. 看起来“_blank”无法在iOS上的外部浏览器中打开网址。 I tried by this: 我试过这个:
1) Install inappbrowser plugin. 1)安装inappbrowser插件。
2) call window.open(encodeURI(' https://openclipart.org/ '), "_blank"); 2)调用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 : 使用“_system”将在iOS上的Safari中打开url,打开url:
1) Install inappbrowser plugin. 1)安装inappbrowser插件。
2) call cordova.InAppBrowser.open(encodeURI(' https://openclipart.org/ '), "_system"); 2)调用cordova.InAppBrowser.open(encodeURI(' https://openclipart.org/ '),“_ system”);
Unfortunately this way only work to send get request. 不幸的是,这种方式只能发送get请求。 Some people suggest submit post form on loadstop event like this: Cordova InAppBrowser post form to url 有人建议在loadstop事件上提交post表单,如下所示: Cordova InAppBrowser将表单发布到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. 当target为“_blank”时,该方法有效,当target为“_system”时,因为浏览器中的open url不是app windows,所以不会触发loadstop事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.