简体   繁体   English

除了我在javascript中指定的方式外,如何防止野生动物园使用命令键?

[英]How do I prevent safari from using the command key other than how I specified it in my javascript?

At the moment, my code uses the command key in combination with other keys to call functions within our javascript. 目前,我的代码结合使用Command键和其他键来调用我们JavaScript中的函数。 This functionality currently works within firefox, however in safari by pressing combinations such as command + "+" or command + "1" it does not do the intended functionality and instead does the functionality inherent to the browser. 该功能目前在Firefox中有效,但是在野生动物园中,通过按诸如Command +“ +”或Command +“ 1”之类的组合,它不会执行预期的功能,而是会执行浏览器固有的功能。 I am currently using the preventDefault() function, which is why this works in firefox, but I am not sure what this does not work in safari. 我目前正在使用preventDefault()函数,这就是为什么它在firefox中可以工作的原因,但是我不确定在Safari中它不能工作的原因。 Any ideas? 有任何想法吗?

I have never been able to convince Safari to let me control command 1 through 9, but event.preventDefault() seems to work fine on - and = when binding to keydown. 我一直无法说服Safari让我控制命令1到9,但是当绑定到keydown时,event.preventDefault()在-和=上似乎可以正常工作。 The normal zoom in/out are suppressed as expected. 正常放大/缩小被抑制。

Try this: 尝试这个:

        if (event.preventDefault) {
           event.preventDefault();
        }
        if (event.stopPropagation) {
            event.stopPropagation();
        }

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

相关问题 如何防止javascript将我的日期转换为GMT? - How do I prevent javascript from converting my dates to GMT? 除了使用下划线键之外,如何使用 xml2js 访问 XML 元素文本? - How do I access the XML element text using xml2js other than using underscore key? 如何从我的 AFK 命令(discord.js)中防止这种情况发生 - How do I prevent this from happening from my AFK Command (discord.js) 如何防止其他网站链接到我的 javascript 文件? - How can I prevent other sites from linking to my javascript files? 如何使用 javascript 从 firebase 中的键中获取值 - How do I fetch the value from a key in firebase using javascript 在 Javascript 中如何防止在 setTimeout 持续时间内调用其他函数? - In Javascript How do I prevent other functions from being invoked while under the setTimeout duration? 如何防止一行JavaScript在IE中运行(但让其在其他浏览器中运行)? - How do I prevent a line of JavaScript from running in IE (but let it run in other browsers)? 如何防止正则表达式匹配 javascript 中的所有其他匹配项 - How do I prevent a regex from matching every other match in javascript 当我在 Javascript 上使用点击事件时,如何防止我的图像消失? - How do I prevent my image from disappearing when I use a click event on Javascript? 如何使用JavaScript删除Mobile Safari的JS文件? - How do I remove a JS file for Mobile Safari using Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM