lagore Active Member Licensed User Longtime User Oct 31, 2011 #1 Hi, Is it possible to use JSInterface to load fields in a web form loaded into a webview. I was hoping to use it to fill 'username & password' and then activate the button click on the web form on a site that I am having trouble doing directly using httpUtils due to a redirection problem I have not sorted yet. Edward
Hi, Is it possible to use JSInterface to load fields in a web form loaded into a webview. I was hoping to use it to fill 'username & password' and then activate the button click on the web form on a site that I am having trouble doing directly using httpUtils due to a redirection problem I have not sorted yet. Edward
warwound Expert Licensed User Longtime User Nov 1, 2011 #2 Hi. If your form is properly constructed it should be possible. Let's say this is your form: Code: Copy <form action="" id="myForm"> <input type="text" value="" name="username" /> <input type="password" value="" name="password" /> <input type="submit" value="Go" /> </form> You can execute javascript to set the inputs values and also call the form's submit() method: Code: Copy <script type="text/javascript"> var myForm=document.forms.myForm; myForm.username.value='Edward'; myForm.password.value='1234567890'; myForm.submit(); </script> To put that all together, you can execute the javascript either using JSInterface and it's execJS() method: Code: Copy Dim myInterface As JSInterface Dim javascript As String javascript="var myForm=document.forms.myForm;myForm.username.value='Edward';myForm.password.value='1234567890';myForm.submit();" myInterface.execJS(myWebView, javascript) OR you can execute the javascript using the WebView's LoadUrl() method: Code: Copy Dim javascript As String javascript="javascript:var myForm=document.forms.myForm;myForm.username.value='Edward';myForm.password.value='1234567890';myForm.submit();" myWebView.LoadUrl(javascript) Martin. Upvote 0
Hi. If your form is properly constructed it should be possible. Let's say this is your form: Code: Copy <form action="" id="myForm"> <input type="text" value="" name="username" /> <input type="password" value="" name="password" /> <input type="submit" value="Go" /> </form> You can execute javascript to set the inputs values and also call the form's submit() method: Code: Copy <script type="text/javascript"> var myForm=document.forms.myForm; myForm.username.value='Edward'; myForm.password.value='1234567890'; myForm.submit(); </script> To put that all together, you can execute the javascript either using JSInterface and it's execJS() method: Code: Copy Dim myInterface As JSInterface Dim javascript As String javascript="var myForm=document.forms.myForm;myForm.username.value='Edward';myForm.password.value='1234567890';myForm.submit();" myInterface.execJS(myWebView, javascript) OR you can execute the javascript using the WebView's LoadUrl() method: Code: Copy Dim javascript As String javascript="javascript:var myForm=document.forms.myForm;myForm.username.value='Edward';myForm.password.value='1234567890';myForm.submit();" myWebView.LoadUrl(javascript) Martin.
lagore Active Member Licensed User Longtime User Nov 1, 2011 #3 Hi Martin, Your code worked perfectly, now I can load the login web page run your bit of JSInterface magic and login to the site which gets over the problem I was having with site redirection. Thanks Edward :sign0098: Upvote 0
Hi Martin, Your code worked perfectly, now I can load the login web page run your bit of JSInterface magic and login to the site which gets over the problem I was having with site redirection. Thanks Edward :sign0098: