[英]How to i stop clients using firefox's search box showing up when playing my HTML5 game with WASD?
I have a question thats semi-related to this question , except for instead of it being from the end-user perspective i need it from the content providers perspective. 我有一个与该问题半相关的问题 ,除了不是从最终用户角度来看,我从内容提供商角度来看都需要它。
I would be surprised if the mozilla foundation would have introduced this semi-intrusive feature with no way of it being disabled for selected content. 如果mozilla基金会引入了这种半侵入式功能而没有为选定的内容禁用该功能,我会感到惊讶。
I have a web page that consists of nothing but a canvas
element which is drawn to via javascript creating a game for the user to play. 我有一个网页,除了canvas
元素之外,其他所有内容都没有,而canvas
元素是通过javascript创建的,供用户玩游戏。 When a user uses the control keys (W, A, S & D) FireFox sees the user is not in some form of input
box and decides they must be wanting to search for something of the page (opening the ctrl+f
search box), forcing the user to lose focus on the game and their following key-presses to go unregistered. 当用户使用控制键(W,A,S和D)时,FireFox看到用户不在某种形式的input
框中,并决定他们必须要搜索页面中的某些内容(打开ctrl+f
搜索框) ,从而迫使用户失去对游戏及其后续按键的关注,从而无法进行注册。 This will pose a problem for non-technical users who do not know where the setting to turn this off is, and in turn they will probably blame it on the content itself rather than it being the browser. 对于不知道将其关闭的设置在哪里的非技术用户,这将构成一个问题,因此他们可能会将其归咎于内容本身,而不是浏览器。 Other than creating a input off the page that the user is force-focused to, is there a way of disabling this while FireFox users are visiting my page? 除了在用户重点关注的页面上创建输入之外,还有什么方法可以在FireFox用户访问我的页面时将其禁用?
After your event is handled just terminate it. 处理完事件后,只需终止它即可。
Example: 例:
function handleDirectionalKeys(ev) {
// .. Your WASD code
ev.preventDefault();
ev.stopPropagation(); // May not be needed, test it yourself
return false;
}
Optionally you can cancel the event when it reaches the top level of the DOM hierachy: (可选)您可以在事件达到DOM层级的最高级别时取消该事件:
$(window).keypress(function(e)
{
// At this point you need to make sure that the key press
// was already handled by your code
e.preventDefault();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.