UIWebView将用户名和密码传递到表单中 [英] UIWebView passing username and password into a form

查看:82
本文介绍了UIWebView将用户名和密码传递到表单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个包含我的大学Intranet页面的UIWebView,我的代码将通过我的用户名罚款(因​​为它是一个数字)

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

谢谢

(这是密码的代码)

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

推荐答案

我想如果您更改此设置:

I think if you change this:

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

对此:

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

它应该工作.请注意,我在%@周围添加了单引号.

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

数字之所以有效,是因为JavaScript将您输入的密码解释为数字.但是,当您在其中放置没有引号的字符串时,它会尝试以密码的一部分(而不是字符串)的身份运行密码.您可能还应该在学生人数字段中加上引号,因为您实际上是在使用数字作为字符串.

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.

这篇关于UIWebView将用户名和密码传递到表单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆