简体   繁体   English

为什么我无法在iframe中的表单元素之间切换?

[英]Why can't I tab between form elements within an iframe?

I have a page in a site that contains an iframe with a form in it. 我在一个站点中有一个页面,其中包含带有表单的iframe。 I can't change this but I do have full control over all of the JS that runs in the parent page and the iframe'd page. 我无法更改此设置,但可以完全控制在父页面和iframe页面中运行的所有JS。

My problem is that when I have a form field focused in the iframe'd document, tabbing to the next field sends the cursor straight up to the address bar of the browser, not the next field in the form. 我的问题是,当我将一个表单字段集中在iframe的文档中时,跳至下一个字段会将光标直接移到浏览器的地址栏,而不是表单中的下一个字段。 Setting tabindexes on each of the fields doesn't help. 在每个字段上设置tabindexes都无济于事。

The browser is treating the entire iframe itself as one of the elements in the page (as it should), but I'm wondering if there's a way to capture the tab events and force focus to stay inside of the iframe and with its child elements. 浏览器将整个iframe本身视为页面中的元素之一(应该如此),但是我想知道是否存在一种方法来捕获选项卡事件并迫使焦点停留在iframe及其子元素中。

Have any of you run into this issue before and have a way around it? 你们有没有遇到过这个问题并且有办法解决?

Not that it will help you, but the layout is something like: 并不是对您有帮助,但是布局是这样的:

+-------------------------------------------+
| Parent page                               |
|         +-------------------------------+ |
|  N      | iframe                        | |
|  a      |                               | |
|  v      | Has about 50 fields that I'd  | |
|  i      | like to be able to tab between| |
|  g      |                               | |
|  a      | But I can't! Help!            | |
|  t      |                               | |
|  i      +-------------------------------+ |
|  o                                        |
|  n                                        |
+-------------------------------------------+

One idea was to try and capture the keydown events in the iframe, check for tab or shift+tab and then refocus the iframe, but then there's the problem of knowing which field I was on before losing focus. 一种想法是尝试捕获iframe中的keydown事件,检查tab或shift + tab,然后重新调整iframe的聚焦,但是问题是在失去焦点之前要知道我所在的字段。 Is there a way to dynamically focus the next field using JS and the tabindex attribute on the form fields? 有没有一种方法可以在表单字段上使用JS和tabindex属性动态关注下一个字段? Perhaps that's where I venture next... 也许那是我下一步的冒险...

Update: perhaps there's something even simpler that I'm missing. 更新:也许我缺少一些更简单的东西。 For example, the login box on http://www.studentloan.com is an iframe and I can tab between those fields just fine. 例如, http://www.studentloan.com上的登录框是iframe,我可以在这些字段之间切换。 Maybe something else in my JS is causing the problem. 也许我的JS中有其他原因导致了问题。

Update 2: I tried loading just the iframe document in the browser as a standalone page and I still can't tab. 更新2:我尝试仅将iframe文档作为独立页面加载到浏览器中,但仍然无法打开标签。 I think it's something I'm doing in JS somewhere else that's causing the document to lose focus. 我认为这是我在JS中其他地方所做的事情,这导致文档失去焦点。 I'll post my solution when I find it. 找到解决方案后,我会发布解决方案。

Update 3: 更新3:

The problem is caused by the Ajax Control Tookit's ModalPopupExtender. 该问题是由Ajax控件Tookit的ModalPopupExtender引起的。 I'm using one as a loading message after calling a webservice. 调用Web服务后,我将其中一个用作加载消息。 It gets hidden when the callback method is fired. 当触发回调方法时,它将被隐藏。

I can tab between the fields until the Modal popup is shown and hidden for the first time. 我可以在字段之间切换,直到第一次显示和隐藏“模态”弹出窗口。 After that, the form can never keep its focus. 之后,表单永远无法保持其焦点。 I'm investigating why and will post an answer if I can find out why. 我正在调查原因,如果可以找出原因,将发布答案。

Thanks! 谢谢!

I had almost the same problem as you. 我和你几乎有同样的问题。 After a lot of time looking for a solution I found this web where I could discover what was causing me this problem: the modalpopupextender. 经过大量时间寻找解决方案后,我找到了这个网站,在这里我可以找到导致此问题的原因:modalpopupextender。 Once I knew what was the real problem, it was pretty easy find the solution. 一旦我知道真正的问题是什么,就很容易找到解决方案。 Here it is: http://forums.asp.net/t/1191142.aspx 在这里是: http : //forums.asp.net/t/1191142.aspx

I hope it helps you to understand this problem as it did for me. 我希望它能像您对我一样帮助您理解此问题。

I imagine using ajax is out the question? 我想象使用ajax是不可能的吗?

If it's not, then you don't have the iframe tabbing issues as your form is part of the current page. 如果不是,那么您就没有iframe制表问题,因为您的表单是当前页面的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM