iOS Objective C - UIWebView AutoFill and Execute

自古美人都是妖i 提交于 2019-12-18 12:03:15

问题


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?

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?

Thanks in advance!

In response to the answer:

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


回答1:


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];

You obviously have to set firstValue and secondValue first.



来源:https://stackoverflow.com/questions/9711246/ios-objective-c-uiwebview-autofill-and-execute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!