[英]UIWebView passing username and password into a form
我设置了包含我的大学Intranet页面的UIWebView,我的代码将通过我的用户名(因为它是数字)
NSString *studentNumber = @"639909";
NSString *javaScriptNumber = @"document.getElementById('username').value=%@;";
javaScriptNumber = [NSString stringWithFormat: javaScriptNumber, studentNumber];
[webViewInt stringByEvaluatingJavaScriptFromString: javaScriptNumber];
但是,当我尝试运行相同的代码来填写密码字段时,它将仅适用于数字,我的密码是文本,因此当我输入文本时,任何内容都不会传递到密码字段中。 但是,如果我将密码设置为全数字,则似乎可以使用。 这段代码中有什么我需要更改以允许它传递所有字符的原因,因为它当前仅传递数字
谢谢
(这是密码的代码)
NSString *password = @"password";
NSString *javaScriptPass = @"document.getElementById('password').value=%@;";
javaScriptPass = [NSString stringWithFormat: javaScriptPass, password];
[webViewInt stringByEvaluatingJavaScriptFromString:javaScriptPass];
我认为如果您更改此设置:
NSString *javaScriptPass = @"document.getElementById('password').value=%@;";
对此:
NSString *javaScriptPass = @"document.getElementById('password').value='%@';";
它应该工作。 注意,我在%@
周围添加了单引号。
数字之所以有效,是因为JavaScript将您输入的密码解释为数字。 但是,当您在其中输入没有引号的字符串时,它会尝试以密码的一部分(而不是字符串)的身份运行密码。 您可能还应该在学生人数字段中加上引号,因为您实际上是在使用数字作为字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.