PhoneGap/ChildBrowser - 将应用程序表单发布到 ChildBrowser
我正在使用 PhoneGap 构建 iPhone 应用程序。我正在使用 ChildBrowser 插件。
如果我的应用程序中有一个带有用户名/密码的表单,我是否可以将这些信息发布到像 www.mydomain.com/login.php 这样的 URL 并在 ChildBrowser 中打开它?
请告诉我。
谢谢。
I am building an iPhone App using PhoneGap. I am using ChildBrowser plugin.
If I have a form in the App with username/pass, is there anyway I can post those information to an URL like www.mydomain.com/login.php and open it in ChildBrowser?
Please let me know.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您当然可以将 GET 参数传递给
childBrowser.showWebPage()
。您可以在应用程序中拦截表单的提交,并收集传递的字段名称和值(假设这是一个登录表单,即用户名和密码),并将它们作为参数传递给在 ChildBrowser 中打开的 URL。
childBrowser.showWebPage('https://www.mydomain.com/login.php?username='+username+'&password='+password)
这是一个用于演示目的的相当简单的版本。不需要太多就能让它变得更好。
当然,问题是它是通过 GET 发送的。如果您的登录表单需要 POST 并且您无法更改它,那么您可能会遇到问题。
编辑:
如果 POST 是您唯一的选择,也许您最好使用 AJAX 发布到表单,而不是使用子浏览器。
You can certainly pass GET parameters to
childBrowser.showWebPage()
.You could intercept the submit of your form in your app and gather up the field names and values passed (assuming this is a login form, so say username and password) and pass them as parameters to the URL opened in ChildBrowser.
childBrowser.showWebPage('https://www.mydomain.com/login.php?username='+username+'&password='+password)
This is a rather unsophisticated version for demonstration purposes. It wouldn't take much to make it better.
The catch is of course that it is being sent via GET. If your login form is expecting POST and you can't change that, you could have a problem.
Edit:
If POST is your only option, perhaps you would be better off using AJAX to post to the form instead of using child browser.
我一直在寻找解决方案,并结束了它的开发。 iPhone 的 childbrowser 中并没有现成的。
所以,这是我添加到插件中的代码。
仅供参考,数据应该是格式如下的字符串: arg1=value1&arg2=value2&foo=bar
ChildbrowserViewController
我在那里添加了以下方法:
ChildbrowserCommand
我在 showWebPage 方法中添加了以下代码:
HTH!
米尔顿.
I was looking for a solution, and ended developing it. This doesn't come out of the box in childbrowser for iPhone.
So, here the code that I added to the plugin.
FYI, data should be a string with the format: arg1=value1&arg2=value2&foo=bar
ChildbrowserViewController
I've added the following method there:
ChildbrowserCommand
I've added the following code in the showWebPage method:
HTH!
Milton.