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

查看:12
本文介绍了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];

你显然必须先设置 firstValuesecondValue.

You obviously have to set firstValue and secondValue first.

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

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