把重点放在浏览器上 [英] Give focus to browser

查看:137
本文介绍了把重点放在浏览器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究键盘辅助功能。我有一个Flash对象,它位于一个页面内,并停止焦点被困在里面,我已经添加了标签监听器,通过 ExternalInterface 来交谈一些JavaScript函数。 / p>

JavaScript通过 tabIndex 查找下一个可用元素,并调用 focus() / code>就可以了。到现在为止还挺好。但是,如果插件是页面上的最后一个可放置项目(或者在反向标签时为第一个项目),则不存在切换到的元素。通常这会把焦点设置到浏览器窗口,所以我想保持这种行为。

因此,我的问题:是否有可能以编程方式专注于浏览器的铬?更好的是,如果我可以模仿向前的向后切换。另外,我希望避免在闪光灯之前/之后添加额外的可放置组件,除非我们可以使它们对鼠标键盘都不可见。



将焦点设置为一个没有文本内容的虚拟锚点,在文档的顶部,似乎工作:

  document.getElementsByTagName( 'A')[0] .focus(); 

http://jsfiddle.net/4NA5u/1/

I'm working on keyboard accessibility. I have a flash object which sits inside a page, and to stop the focus getting trapped inside it, I've added tab listeners which talk through ExternalInterface to some JavaScript functions.

The JavaScript looks for the next available element with a tabIndex and calls focus() on it. So far so good. But if the plugin is the last tabbable item on the page (or first when reverse-tabbing), there is no element to switch to. Normally this would set focus to the browser window, so I'd like to keep that behaviour.

Hence my question: Is it possible to programatically give focus to the browser's chrome? Even better if I can mimic both forward and backward tabbing. Also I'd like to avoid adding extra tabbable components before/after the flash if possible, unless I can make them effectively invisible to both the mouse and keyboard.

解决方案

Setting the focus to a dummy anchor with no text content, at the top of the document, seems to work:

document.getElementsByTagName('a')[0].focus();

http://jsfiddle.net/4NA5u/1/.

这篇关于把重点放在浏览器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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