Develop
2003.04.23 10:51
[js] 핫키(단축키) 구현방법
Views 7654 Comment 0
웹 페이지 상에서 특정 행동을 수행하기 위한 단축 키를 보통 핫 키(Hot Key)라고 부른다. 예를 들어, 현재 페이지 상에서 "k" 키를 누르면 코리아인터넷닷컴 홈페이지로 이동할 수 있도록 스크립트를 작성할 수가 있다. 물론, 응용하기에 따라 다양한 효과를 구현할 수 있을 것이다. 다음과 같은 예를 한 번 살펴 보자:
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
var NS = (window.Event) ? 1 : 0
function checkKey(e) {
var code = (NS) ? e.which : event.keyCode;
var key = String.fromCharCode(code);
for (var i = 0{
if (key == ar[i].key) location.href = ar[i].url;
}
}
function hotKey(key, url) {
this.key = key;
this.url = url;
}
if (NS) document.captureEvents(Event.KEYPRESS)
document.onkeypress = checkKey;
var ar = new Array();
ar[ar.length] = new hotKey("k", "http://korea.internet.com/");
ar[ar.length] = new hotKey("j", "http://korea.internet.com/channel/list.asp?cid=189&zid=8");
ar[ar.length] = new hotKey("h", "http://korea.internet.com/channel/list.asp?cid=187&zid=8");
// -->
</SCRIPT>
위와 같은 방법으로 다양한 핫키를 정의할 수가 있다. 이런 정의는 인터넷 익스플로러 4.x 이상과 넷스케이프 내비게이터 4.x 이상에서만 사용할 수가 있다.
현재 페이지에서 j키, h키, k키를 각각 눌러 보기 바란다. 아마도 해당 페이지로 이동하게 될 것이다.
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
85 | Develop | [android] Android N requires the IDE to be running with Java 1.8 or later 오류 | hooni | 2016.08.30 | 953 |
84 | Develop | [c] 셀프 넘버(Self Number) 구하기 1 | hooni | 2016.09.09 | 2393 |
83 | Develop | [c] Mac OS 에 gmp(gmp.h) 라이브러리 설치 | hooni | 2016.10.03 | 1444 |
82 | Develop | [c] RSA 암호화 구현(gmp 라이브러리 활용) | hooni | 2016.10.03 | 1017 |
81 | Develop | [matlab] 정보은닉 스테가노그래피(Steganography) 수업 | hooni | 2016.10.03 | 791 |
80 | Develop | [matlab] ZigZag-Scanning (2-D Array) | hooni | 2016.10.15 | 2117 |
79 | Develop | [android] dp, px 서로 변환 | hooni | 2016.10.21 | 3504 |
78 | Develop | [android] 초간단 얼럿 (AlertDialog) | hooni | 2016.10.21 | 941 |
77 | Develop | [android] 레이아웃 사이즈 변경 (동적; programmatically) | hooni | 2016.11.07 | 1621 |
76 | Develop | [Android Error] The number of method references in a .dex file cannot exceed 64K | hooni | 2016.11.10 | 897 |
75 | Develop | [android] Calling activity function from separate class | hooni | 2016.11.15 | 1314 |
74 | Develop | [android] How can I place app icon on launcher home screen? | hooni | 2016.11.15 | 1414 |