私のアプリでは、ユーザーにカスタム表示でログイン情報を入力させてから、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>
: は、ここで私がアクセスしようとしているウェブサイトのソースコードです。
ご協力いただければ幸いです。 ありがとうございます。
EDIT ので、私はこれらを試したし、それらのどれも動作しません:
[webView stringByEvaluatingJavaScriptFromString:@"document.myForm.myText.value='text from Obj-C';"];
[webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('L$lbsc$txtUserName').value='ANdrew';"];
ありがとうございます。これをどのような方法で入れるべきですか? viewDidLoad、webViewDidFinishLoad? – Andrew
コンテンツにアクセスする前にページの読み込みが完了している必要がありますので、 'webViewDidFinishLoad:'はおそらくそれを置くのに適しています。 – Jim
私はそれを試みましたが、それは動作していないようです。それが動作している場合は、UIWebViewに表示されません。ビューや何かをリロードする必要がありますか? – Andrew