在 Firefox 中覆盖 Facebook 的 Ctrl+M 热键
我正在开发一个小书签,它允许用户用我们的语言在任何输入字段上书写。我们选择 Ctrl+M
在默认语言和我们的语言之间切换布局(受维基百科启发)。它在几乎每个使用 Chrome 的网站上都运行良好。当我们开始使用 Firefox 检查时,我们发现它仅在 Facebook 中失败。
此外,Facebook 从
窗口
外部捕获Ctrl+M
范围。例如,形成地址栏、搜索栏、firebug 控制台等。
我尝试过使用原始 javascript、jQuery 以及 jQuery 热键 插件由 John Resig</a> 但没有运气:(
这是我尝试过的版本。您可以在 Firebug 控制台上运行它测试目的-
(function(){
var noConflictMode = false;
if(typeof $ !== 'undefined') noConflictMode = true;
if(typeof jQuery === 'undefined') {
var root = (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]);
var ns = document.createElementNS && document.documentElement.namespaceURI;
var script = ns ? document.createElementNS(ns, 'script') : document.createElement('script');
script.type = 'text/javascript';
script.onreadystatechange = function () {
if (this.readyState == 'complete') test();
}
script.onload= test;
script.src= 'https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js';
root.appendChild(script);
} else {
test();
}
function test() {
if(noConflictMode) jQuery.noConflict();
jQuery(window).on('keydown keyup keypress', function(e){
e.preventDefault();
// For Firefox
e.stopPropagation();
// Extra effort :|
e.stopImmediatePropagation()
e.cancelBubble = true;
console.log(e);
return false;
});
}
})();
I'm working on a bookmarklet which will let users to write on any input fields in our language. We choose Ctrl+M
for switching layout between default and our language (Inspired by Wikipedia). It was working fine in almost every website with chrome. When we started checking with Firefox we found that it only fails in Facebook.
Moreover, Facebook catches the
Ctrl+M
from outside thewindow
scope. Like, form the address bar, search bar, firebug console, etc.
I've tried with raw javascript, jQuery and also with the jQuery Hotkeys plugin by John Resig but no luck :(
Here is a version that I had tried. You can run it on your Firebug console for testing purpose -
(function(){
var noConflictMode = false;
if(typeof $ !== 'undefined') noConflictMode = true;
if(typeof jQuery === 'undefined') {
var root = (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]);
var ns = document.createElementNS && document.documentElement.namespaceURI;
var script = ns ? document.createElementNS(ns, 'script') : document.createElement('script');
script.type = 'text/javascript';
script.onreadystatechange = function () {
if (this.readyState == 'complete') test();
}
script.onload= test;
script.src= 'https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js';
root.appendChild(script);
} else {
test();
}
function test() {
if(noConflictMode) jQuery.noConflict();
jQuery(window).on('keydown keyup keypress', function(e){
e.preventDefault();
// For Firefox
e.stopPropagation();
// Extra effort :|
e.stopImmediatePropagation()
e.cancelBubble = true;
console.log(e);
return false;
});
}
})();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出于安全原因,您不能在客户端 Web 上执行此操作,您可以使用 JS 或 JQ 或您想要的任何语言编写任何内容,但 MOZ 永远不会处理您的代码。
请注意,一件事是浏览器“编译”您的代码并使用它,另一件事是您可以更改浏览器本身。由于这个原因,就有了“附加组件”。
例如,您无法在 VS 中更改 Visual Studio 编程的内核:D
但是...
...您可以要求用户重新绑定密钥,您有 3 种方法可以做到这一点:
1)安装 MOZ插件(或您自己的插件)
2)使用:http://mxr.mozilla.org/seamonkey/source/dom/public/idl/events/nsIDOMKeyEvent.idl
3) 在操作系统级别安装比应用程序优先级更高的快捷键b (在本例中为 MOZ)(您可以使用 C# 来完成)。 Alt+tab 组合是高级快捷方式的一个示例,或“Prnt Scrn”,
使用 about:config 也无法做到这一点。
也许这个网址可以帮助你,但我建议你尝试要求 MOZ 中的更改而不是要求 Javascript 代码。
http://www-archive.mozilla.org/unix/customizing.html#keys
You can NOT do that on client-side web for security reasons, you can code anything in JS or JQ or any language you want but MOZ never will take care of your code.
Take care, one thing is that the browser "compile" your code and work with it, and another thing is that you can change the browser itself. For that reasons there's the "add-on".
For example, you can't change the kernel of Visual Studio programming in V.S. :D
BUT...
... you can ask to the user re-bind the keys, you have 3 ways to do that:
1) installing a MOZ add-on (or your own addon)
2) Working with: http://mxr.mozilla.org/seamonkey/source/dom/public/idl/events/nsIDOMKeyEvent.idl
3) installing a shortcut keyb at OS level with higher priority than the App (in this case, MOZ) (you can do it with C#). Alt+tab combination is an example of high level shortcut, or "Prnt Scrn"
There is NO way to do that with about:config, neither.
Maybe this url can help you, but i suggest you try asking for changes in MOZ and not asking for Javascript code.
http://www-archive.mozilla.org/unix/customizing.html#keys