iOS Objective C - UIWebView自动填充和执行 [英] iOS Objective C - UIWebView AutoFill and Execute

查看:73
本文介绍了iOS Objective C - UIWebView自动填充和执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何可能的方法可以让webview自动输入网站上文本框的值并提交,以便用户可以完全绕过搜索(特别是搜索表单)?那么用户只显示结果?

I was wondering is there any possible way that I can have a webview that automatically inputs the values for text boxes on a website and submit so that the user can just bypass the search (in particular search forms) entirely? So the user is only shown the result?

一个例子是: http://www.eatwellguide.org/mobile/
我注意到它使用的是javascript来源。

An example is : http://www.eatwellguide.org/mobile/ I noticed looking at the source it is using javascript.

有没有无论如何,我可以自动填写并按下提交,用户甚至不会看到此页面。那么,网页加载到结果页面?

Is there anyway I can automatically fill those in and press submit without the user even seeing this page. So, the webpage loads up to the results page?

提前致谢!

回答答案:

我有什么具体的地方可以放这个代码吗?我在上面列出的网站对webView加载请求之后然后在[super viewDidLoad]之后,我把你列出的代码放入第一个值和第二个值的值,其中nameofOneInput是'SearchKeyword', 'SearchSubmit'是第二个,然后表单ID为'frmsAS'?它仍然无法正常工作。我究竟做错了什么?我实际上尝试按下a按钮时执行它仍然无法正常工作

Is there any specific place I have to put this code? I put it after I did a load request to the webView for the site I listed above and then after the [super viewDidLoad], I put in the code you listed with values for first value and second value, with nameofOneInput being 'SearchKeyword', 'SearchSubmit' being the 2nd, and then the form id as 'frmsAS'? It's still not working. What am I doing wrong? I actually tried it to execute when the a button is pressed, still did not work

推荐答案

是的,你可以使用下面的javascript填写表格然后提交。

Yes, you can use the following javascript to fill out the form then submit it.

//Set the values
NSString* firstValue = @"first value here";
NSString* secondValue = @"second value here";
// write javascript code in a string
NSString* javaScriptString = @"document.getElementById('nameOfOneInput').value=%@;"
"document.getElementById('nameOfAnotherInput').value=%@;"
"document.forms['nameOfForm'].submit();";

// insert string values into javascript
javaScriptString = [NSString stringWithFormat: javascriptString, firstValue, secondValue];

// run javascript in webview:
[webView stringByEvaluatingJavaScriptFromString: javaScriptString];

你显然必须设置 firstValue secondValue 首先。

You obviously have to set firstValue and secondValue first.

这篇关于iOS Objective C - UIWebView自动填充和执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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