NimbleKit - fast iOS app development

Modify NKWebview Output

Ask questions and share your skills here

Modify NKWebview Output

Postby bAstimc » Fri May 18, 2012 1:32 pm

Hey,
i set up a NKWebview and i want to autofill the form + submit.

I used the webView.setOnFinishCallback option to start a function but how can i point the functions to the Webview inputfields?

$('#userName').val('testname');
$('#userPassword').val('testpw');
$('#mainForm').submit();

those lines dont work, but in firefox' js notepad they do :(


greetz
bAstimc
 
Posts: 39
Joined: Wed May 16, 2012 7:44 am

Re: Modify NKWebview Output

Postby ryubr » Fri May 18, 2012 8:13 pm

The callback is to run something after the webview is loaded, but the code to be executed is on the app scope, so if you need to run code on the webview scope. use the onload method on the body to run the code ;-) Simple as that :-)
ryubr
NimbleKit Expert
 
Posts: 445
Joined: Fri Jun 19, 2009 5:36 am

Re: Modify NKWebview Output

Postby bAstimc » Sat May 19, 2012 12:46 pm

Code: Select all
webView.onload("$('#userPassword').val('testpw')");

thats the only way i could think of... but the webview turns white and empty :roll:

body onload is only for the app scope and it wont work...

i hoped there would be an easy way like NKExecuteJavascriptOnWebview or something :lol:
bAstimc
 
Posts: 39
Joined: Wed May 16, 2012 7:44 am

Re: Modify NKWebview Output

Postby ryubr » Mon May 21, 2012 6:10 pm

Actually I meant that you use the standard onload on the body of the page, not the page of the app, but the page on the webview you loaded like this:

Code: Select all
<body onload="somefunction()">


Or in script block:
Code: Select all
<script>
window.onload = function()
{
   //run some javascript code here
}
</script>


From within the app you don´t have access to the Webiview DOM, so you got to run the code in the page scope this case the Webiview page, this is why the onload works ;-) If you have to pass parameters to the poage you could use get paramenters to the ul to get them there and use as you fit
ryubr
NimbleKit Expert
 
Posts: 445
Joined: Fri Jun 19, 2009 5:36 am

Re: Modify NKWebview Output

Postby bAstimc » Tue May 22, 2012 8:27 am

ye the thing is that the website in webview isnt mine... so i cant use body onload etc...
ok then I'll have to autologin it otherwise. :o
maybe with post... somehow..
url login via get isnt working
bAstimc
 
Posts: 39
Joined: Wed May 16, 2012 7:44 am

Re: Modify NKWebview Output

Postby bAstimc » Thu May 24, 2012 9:09 am

:? mh there has to exist a solution :x
bAstimc
 
Posts: 39
Joined: Wed May 16, 2012 7:44 am


Return to How To...

Who is online

Users browsing this forum: No registered users and 1 guest