UIWebView passing username and password into a form

无人久伴 提交于 2019-12-11 13:52:14

问题


I have a UIWebView set up containing my universitys intranet page, my code will pass in my username fine (as it is a number)

NSString *studentNumber = @"639909";
NSString *javaScriptNumber = @"document.getElementById('username').value=%@;";
javaScriptNumber = [NSString stringWithFormat: javaScriptNumber, studentNumber];
[webViewInt stringByEvaluatingJavaScriptFromString: javaScriptNumber];

However when i try to run the same code to fill in the password field, it will only work with numbers, my password is text so when I enter text nothing will pass into the password field. However if I set my password to be all numbers it seems to work. Is there something in this code I need to change to allow it to pass all characters as it currently only passes numbers

Thankyou

(This is the code for the password)

  NSString *password = @"password";
NSString *javaScriptPass = @"document.getElementById('password').value=%@;";
javaScriptPass = [NSString stringWithFormat: javaScriptPass, password];
[webViewInt stringByEvaluatingJavaScriptFromString:javaScriptPass];

回答1:


I think if you change this:

NSString *javaScriptPass = @"document.getElementById('password').value=%@;";

to this:

NSString *javaScriptPass = @"document.getElementById('password').value='%@';";

it should work. Notice that I added single quotes around %@.

Numbers worked because the JavaScript interpreted the password you entered as a number; however, when you put a string in there with no quotes, it's tries to run you password like it's part of the code instead of as a string. You should probably add the quotes for the student number field too, since you are really using the number as a string.



来源:https://stackoverflow.com/questions/15837266/uiwebview-passing-username-and-password-into-a-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!