Ala*_*lan 3 javascript iphone objective-c uiwebview ios
我想知道有没有可能的方法,我可以有一个webview自动输入网站上的文本框的值并提交,以便用户可以完全绕过搜索(特别是搜索表单)?那么用户只显示结果?
一个例子是:http://www.eatwellguide.org/mobile/ 我注意到它正在使用javascript查看源代码.
无论如何,我可以自动填写并按下提交,用户甚至不会看到此页面.那么,网页加载到结果页面?
提前致谢!
回答答案:
我有什么具体的地方可以放这个代码吗?在我对上面列出的网站的webView加载请求之后,然后在[super viewDidLoad]之后,我把它放在你列出的代码中,其中包含第一个值和第二个值,nameofOneInput是'SearchKeyword', 'SearchSubmit'是第二个,然后表单ID为'frmsAS'?它仍然无法正常工作.我究竟做错了什么?我实际上尝试按下按钮时执行,仍然无法正常工作
是的,您可以使用以下javascript填写表单然后提交.
//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];
Run Code Online (Sandbox Code Playgroud)
显然,你必须设置firstValue和secondValue第一.
| 归档时间: |
|
| 查看次数: |
3318 次 |
| 最近记录: |