admin管理员组文章数量:1314574
I created one Asp MVC4 web application using C# which we can dynamically create keyboard shortcuts for all the pages.And we can use that keyboard shortcuts instantly to go to specific page.And the problem is every browser have their own default shortcuts.For example
If I create the keyboard shortcut CTRL + A it should redirect to my own custom page. But the default browser shortcut CTRL + A selects all from the page instead.
I want to disable the default browser shortcuts to give priority to my own custom shortcuts.Is this any way to achieve these? For my custom shortcuts,i used jquery keyUp event.I searched on internet,there suggestion are on jquery keyUp event,use preventDefault().But for accessing my own custom shortcuts,i am using keyUp event.So tell me suggestions to disable default browser shortcuts in all browsers either by C#, jquery or any other way.
I created one Asp MVC4 web application using C# which we can dynamically create keyboard shortcuts for all the pages.And we can use that keyboard shortcuts instantly to go to specific page.And the problem is every browser have their own default shortcuts.For example
If I create the keyboard shortcut CTRL + A it should redirect to my own custom page. But the default browser shortcut CTRL + A selects all from the page instead.
I want to disable the default browser shortcuts to give priority to my own custom shortcuts.Is this any way to achieve these? For my custom shortcuts,i used jquery keyUp event.I searched on internet,there suggestion are on jquery keyUp event,use preventDefault().But for accessing my own custom shortcuts,i am using keyUp event.So tell me suggestions to disable default browser shortcuts in all browsers either by C#, jquery or any other way.
Share Improve this question edited Feb 24, 2015 at 9:56 Rory McCrossan 338k41 gold badges320 silver badges351 bronze badges asked Feb 24, 2015 at 9:51 venkivenki 3032 silver badges10 bronze badges 1-
I'm pretty sure this is not possible, at the very least it won't work reliably accross all browsers. You can listen to key events using
keydown
and check the event to see if CTRL was pressed, but the browser chrome will override any shortcuts you make in JS. – Rory McCrossan Commented Feb 24, 2015 at 9:59
2 Answers
Reset to default 9This will let you do this:
e.ctrlKey && String.fromCharCode(kc).toUpperCase()
checks for Ctrl + A to be pressed.
$(document).on('keydown', function(e) {
var kc = e.which || e.keyCode;
if (e.ctrlKey && String.fromCharCode(kc).toUpperCase() == "A") {
e.preventDefault();
console.log(String.fromCharCode(kc).toUpperCase());
window.location.href = 'your url here';
}
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
adfasfasdfsda
You should click in the document to focus and then you can test it.
You had the procedure correct. I guess you can use ascii values to manipulate such things for eg: I use this for pressing enter key.
$('body').on('keypress', '#Selector-Id', function(e) {
if (e.which == 13) {
alert("Hi");
}
});
本文标签: javascriptOverride the browser shortcuts by my own custom shortcutsStack Overflow
版权声明:本文标题:javascript - Override the browser shortcuts by my own custom shortcuts - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741963612a2407422.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论