如何防止在Cordova的浏览器中打开外部链接? [英] How to prevent to open external link in browser in cordova?

查看:105
本文介绍了如何防止在Cordova的浏览器中打开外部链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将cord2与cordova一起用于android应用.在此,我正在使用支付网关,因此,我需要在不打开浏览器的情况下将表单值发布到外部支付URL.

I am using angular2 with cordova for android app. In this I'm using payment gateway so, to do this I need to post form values to external payment URL without opening browser.

示例代码为:

<form action="<External URL>" method="POST">
      <input type="text" value="paymentID">
</form>

请帮助我.

推荐答案

要使表单提交无法在浏览器中打开,您必须允许导航到该URL. 您可以通过在config.xml中添加allow-navigation条目(例如<allow-navigation href="http://example.com/*" />)来实现.

To make the form submit not open in browser you have to allow navigation to that url. You can do it by adding an allow-navigation entry in your config.xml like this <allow-navigation href="http://example.com/*" />.

在Android中,您还需要安装cordova-plugin-whitelist

In Android you will also need to install cordova-plugin-whitelist

但是您不应真正将表单提交到外部URL,而应使用XHR(AJAX)将POST发送到服务器,而不是将表单提交给服务器.

But you should not really do a form submit to an external url, you should use XHR (AJAX) to send the POST to the server instead of the form submit.

这篇关于如何防止在Cordova的浏览器中打开外部链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆