Assign Shortcut key for ASP.Net Page Using Javascript
Shortcut key gives end user more friendly interactions and performance. In this blog I will demonstrate how to implement a shortcut key access for ASP.NET page controls, using Javascript.
Detecting keystrokesThe key point here is to capture window event of web browser.
As we all know, browser vendors start experimenting when there's no official standard, and these experiments, though occasionally useful, also cause incompatibilities. The key events are no exception: there are currently two properties that give information about the pressed keys, and although there's some justification for this duplication, not all browsers support them in the same way.
In addition, there are a few important differences between the keydown and keyup events on one hand, and the keypress event on the other.
Finally, there are important differences between Windows and Mac. In general, detecting keys on Mac is much, much more difficult than on Windows.
keyCode and charCode
The two properties are keyCode
and charCode
. Put (too) simply, keyCode
says something about the actual keyboard key the user pressed, while charCode
gives the ASCII value of the resulting character. These bits of information need not be the same; for instance, a lower case 'a' and an upper case 'A' have the same keyCode
, because the user presses the same key, but a different charCode
because the resulting character is different.
Explorer and Opera do not support charCode
. However, they give the character information in keyCode
, but only onkeypress. Onkeydown and -up keyCode
contains key information.
ShortCut Key Implement
1. shortcutkey.js
if(window.captureEvents) {
window.captureEvents(Event.KeyUp);
window.onkeyup = executeCode;
}
else if (window.attachEvent) {
document.attachEvent('onkeyup', executeCode);
}
function executeCode(evt) {
if(evt==null) {
evt = window.event;
} // IE doesn't pass the event object to the event listener.
var theKey = parseInt(evt.keyCode,10);
//alert(theKey);
switch(theKey) {
case 76: // L
//if (window.event.altKey)
document.getElementById('linkToSina').click(); break;
case 69: // E
//if (window.event.altKey)
document.getElementById('linkToSohu').click();
break;
case 67: // C
//if (window.event.altKey)
document.getElementById('linkToGoogle').click(); break;
case 65: // A
//if (window.event.altKey)
document.getElementById('linkToBaidu').click(); break;
case 83: // S
//if (window.event.altKey)
document.getElementById('linkToMicrosoft').click(); break;
case 78: // Alt + N
if (window.event.altKey) document.getElementById('linkToItpub').click();
break;
}
evt.returnValue = false;
return false;
}
function GoTo(url) {
window.open(url,'','width=600,height=400');
}
2. ASP.NET Page
相關文章
- Iterm2 keyboard shortcut
- List all javascript events wired up on a page using jqueryJavaScriptjQuery
- ASP.NET Web Page Resources OverviewASP.NETWebView
- [翻譯]使用 ICS KeyChain API(Using the ICS KeyChain API)AIAPI
- Partitioned Linux Block Devic Using UDEV And Assign Them To ASM_1528148.1LinuxBloCdevASM
- [Javascript] Perform Set Operations using JavaScript Set MethodsJavaScriptORM
- JavaScript keypress 事件JavaScript事件
- JavaScript keydown 事件JavaScript事件
- JavaScript keyup 事件JavaScript事件
- How to: Select an Encoding for ASP.NET Web Page GlobalizationEncodingASP.NETWeb
- How to: Set the Culture and UI Culture for ASP.NET Web Page GlobalizationUIASP.NETWeb
- Agent admitted failure to sign using the key解決MITAI
- asp.net中Page.ClientScript.RegisterStartupScript用法小結ASP.NETclient
- HTML Layout Guidelines for ASP.NET Web Page GlobalizationHTMLGUIIDEASP.NETWeb
- ASP.NET Page函式呼叫順序及解釋ASP.NET函式
- 重學 JavaScript API - Page Visibility APIJavaScriptAPI
- JavaScript 陣列 keys()JavaScript陣列
- JavaScript event.metaKeyJavaScript
- JavaScript event.shiftKeyJavaScript
- JavaScript event.ctrlKeyJavaScript
- JavaScript event.altKeyJavaScript
- [Javascript] Reflect vs obj[key]JavaScriptOBJ
- [Javascript] Find Items from the end of the JavaScript Array using at, findLast and findLastIndexJavaScriptASTIndex
- Object assign()Object
- JavaScript event.keyCodeJavaScript
- JavaScript keydown事件總結JavaScript事件
- Using NInject Do DI(3) In Asp.net MVC4ASP.NETMVC
- 使用 Angular Shortcut 匯入 style 檔案Angular
- shortcut switch in terminal start pos & end pos
- ASP.NET的Page.IsPostBack 屬性詳細說明(轉)ASP.NET
- object.assignObject
- JSON Web Token in ASP.NET Web API 2 using OwinJSONWebASP.NETAPI
- Asp.net 2.0 傳送Email(Using System.web.Mail)ASP.NETAIWeb
- 建立,刪除快捷圖示shortcut android .Android
- Send Push Notifications to iOS Devices using Xcode 8 and Swift 3, APNs Auth KeyiOSdevXCodeSwift
- Object.assign 模組Object
- Object.assign()方法Object
- C++:vector assignC++