我试图为基于浏览器的应用程序实现 CTRL+S 功能.我进行了搜索,并在以下问题中遇到了两个脚本
I was trying to implement the CTRL+S feature for a browser based application. I made a search and came across two scripts in the following to questions
捕获 CTRL+S 的最佳跨浏览器方法jQuery?
Ctrl+S preventDefault 在 Chrome 中
但是,当我尝试实现它时,它工作了,但我仍然得到默认浏览器保存对话框/窗口.
However, when I tried to implement it, it worked but, I still get the default browser save dialog box/window.
我的代码:对于 shortcut.js:
shortcut.add("Ctrl+S",function() {
alert("Hi there!");
},
{
'type':'keydown',
'propagate':false,
'target':document
});
jQuery 热键.js:
jQuery hotkeys.js:
$(document).bind('keydown', 'ctrl+s', function(e) {
e.preventDefault();
alert('Ctrl+S');
return false;
});
我相信 e.preventDefault(); 应该可以解决问题,但由于某种原因它不起作用.我哪里错了.对不起,如果很简单,还在学习jJvascript.
I believe e.preventDefault(); should do the trick, but for some reason it doesn't work. Where am I going wrong.Sorry if it is simple, still learning jJvascript.
这只是为我使用的问题添加不同的实现.改编自 SO 答案.也适用于 MAC
This is to just add a different implementation to the question used by me. Adapted from a SO answer.Also,works for MAC
document.addEventListener("keydown", function(e) {
if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
e.preventDefault();
//your implementation or function calls
}
}, false);
这篇关于处理浏览器的“ctrl+s"按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
在 Angular 2/Typescript 中使用 IScrollUse IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
Anime.js 在 Ionic 3 项目中不起作用anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 项目中不起作用)
Ionic 3 - 使用异步数据更新 ObservableIonic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用异步数据更新 Observable)
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
将 ViewChild 用于动态元素 - Angular 2 &离子2Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(将 ViewChild 用于动态元素 - Angular 2 amp;离子2)