开发者

Opera redirect problem

Hi everyone i have a problem like this.

For example im in http://localhost/Search.aspx I have 2 textboxes (txtUserName and txtPassword) in my page for login. user can press enter key to call Login() method when any o开发者_运维技巧f these textboxes focused. I capture enter key like this

txtUserName.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {Login();return false;}} else {return true}; ");
txtPassword.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {Login();return false;}} else {return true}; ");

Its calling the Login() method, and After doing that method Opera redirects the page to my default page (http://localhost/Default.aspx)

Other browsers is working as it should, in other words they are not redirect me to the default page.

Opera version 10.61


Alright, so you're problem here is Opera (bless it) doesn't support the onKeyDown command very well - so you have to look at onKeyUp or onKeyPress instead. There's a really handy HTML table on quirksmode explaining this.

Given you're only trying to trap a control key onKeyUp is probably your best bet. I've been forced to combine onKeyDown and onKeyPress in order to catch text input AND control keys (but since you want text input to work as normal you don't need to go this far).

It should be simply a matter of switching "onkeydown" to "onkeyup" in your example fragment.

There is, perhaps, a question of why you'd be doing the above. I don't know what Login() does, but building a form with 3 parts (input-text, input-password, and input-submit button) will -by default- submit the form when enter is pressed in either of the input boxes, you could just add an onSubmit event to the form calling Login();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜