在我的应用程序中,我希望能够让用户在自定义视图中输入其登录信息,然后显示UIWebView。我希望用户的用户名和密码以编程方式填写UIWebView。然后,UIWebView应该以编程方式点击登录按钮。我一直在尝试:以编程方式在UIWebview中填充数据
[webView stringByEvaluatingJavaScriptFromString:@"document.L_lbsc_txtUserName.text.value='ANdrew';"];
但它不工作。我并不十分了解stringByEvaluatingJavaScriptFromString
的工作原理或设计目的。
我认为这可能与我在上面的字符串字段中填充的内容有关。 这里是网站,我试图访问的源代码:
<div class="lgntxt">
<div style="padding-left:3px;">
<input name="L$lbsc$txtUserName" type="text" value=" -username-" size="10" id="L_lbsc_txtUserName" tabindex="1" class="textbox" onfocus="if(this.value == ' -username-') this.value = ''; Hide('L_lbsc_txtPasswordHelp'); Show('L_lbsc_txtPassword');" onblur="if(this.value == '') this.value = ' -username-';" style="width:80px;"><br>
<img src="/podium/images/spacer.gif" border="0" width="3" height="1"><br>
<input name="L$lbsc$txtPasswordHelp" type="text" value=" -password-" size="10" id="L_lbsc_txtPasswordHelp" tabindex="1" class="textbox" onfocus="Hide('L_lbsc_txtPasswordHelp'); Show('L_lbsc_txtPassword'); document.getElementById('L_lbsc_txtPassword').focus();" style="width:80px;display:;">
<input name="L$lbsc$txtPassword" type="password" size="10" id="L_lbsc_txtPassword" tabindex="2" class="textbox" onkeydown="if ((event.which ? event.which : event.keyCode) == 13) {return false;};" onkeyup="if ((event.which ? event.which : event.keyCode) == 13) {__doPostBack('L$lbsc$btnLogin','');return false;};" onblur="if(this.value == '') {Show('L_lbsc_txtPasswordHelp'); Hide('L_lbsc_txtPassword');}" style="width:80px;display:none;">
</div>
</div>
我想更换用户名和密码字段。
任何帮助将不胜感激。 在此先感谢。
编辑 所以我已经试过这和他们没有工作:
[webView stringByEvaluatingJavaScriptFromString:@"document.myForm.myText.value='text from Obj-C';"];
[webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('L$lbsc$txtUserName').value='ANdrew';"];
非常感谢。我应该使用什么方法? viewDidLoad,webViewDidFinishLoad? – Andrew 2011-03-06 02:24:12
好吧,它需要页面完成加载才能访问它的内容,所以'webViewDidFinishLoad:'可能是放置它的适当位置。 – Jim 2011-03-06 02:34:05
我试过了,它似乎没有工作。如果它在UIWebView中没有显示出来。我是否需要重新加载视图或其他内容? – Andrew 2011-03-06 03:39:37