简体   繁体   English

在WASD上播放HTML5游戏时,如何使用显示的firefox搜索框阻止客户?

[英]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.

相关问题 html5游戏正在玩时如何停止滚动? - How to stop scrolling while html5 game is playing? 如何停止同时播放HTML5 / JavaScript音轨 - How do I stop my HTML5/JavaScript audio tracks from playing at the same time 用户滚动到html5时如何开始播放我的视频? - how can I start playing my video in html5 when user scrolls to it? 在玩游戏时,如何阻止我的网站通过箭头键上下滚动? - How do I stop my website from scrolling up and down with the arrow keys when playing games? 即使从iPad iOS7中的DOM中删除了HTML5音频,我该如何停止播放 - How do I stop HTML5 audio from playing even when removed from the DOM in iPad iOS7 如何加快html5游戏 - how to speed up html5 game 如何使用HTML5 Canvas而不是Debug Draw绘制我的Box2D世界? - How do I draw my Box2D world using HTML5 Canvas instead of Debug Draw? 我的HTML5游戏不时停顿,我怎样才能知道它是否是垃圾收集引起的? - My HTML5 game pauses from time to time, how can I find out if it's caused by garbage collection? 如何让屏幕阅读器停止将 HTML5 游戏视为文档? - How can I get a screen reader to stop treating an HTML5 game like a document? html5视频无法在Apple机器上的Firefox中播放 - html5 video not playing in firefox on Apple machinees
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM