웹마스터 팁
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
자바스크립트 단축키 지정을 쉽게하자.
2005.02.14 22:39
Firefox및 IE에서 모두 동작하는 방법으로 저쪽 javaScript 게시판에서 본 방법을 php를 써서 재사용하기 쉽게 고쳐봤습니다. html에서 h키를 누르면 www.nzeo.com이 뜨는 소스.
<?php
include "keystroke.php";
?>
<html>
<body>
<?php
beginKeyStroke();
addKeyStroke("h", "http://www.nzeo.com");
addKeyStroke("f", "http://www.firefox.org");
endKeyStroke();
?>
....
</body>
</html>
즉, 바디의 시작 부분에 keystroke를 정의해 줍니다.
keystroke.php->
function beginKeyStroke()
{
echo <<<MYHTMLSAFEOUTPUT
<SCRIPT LANGUAGE="JavaScript1.2">
var NS = (window.Event) ? 1 : 0
function checkKey(e) {
if (e == null) {
code = event.keyCode;
if(event.srcElement.tagName == "INPUT" || event.srcElement.tagName == "TEXTAREA") return true;
}
else {
if (e.altKey || e.ctrlKey) {
return true;
}
if(e.target.tagName == "INPUT" || e.target.tagName == "TEXTAREA") return;
code = e.which;
}
key = String.fromCharCode(code).toLowerCase();
if(code==13) key="enter";
var code = (NS) ? e.which : event.keyCode;
var key = String.fromCharCode(code);
for (var i = 0; i < ar.length; i++) {
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();
MYHTMLSAFEOUTPUT;
echo "n";
}
function addKeyStroke($key, $addr)
{
echo "ar[ar.length] = new hotKey("$key","$addr");n";
}
function endKeyStroke()
{
echo "</SCRIPT>";
}
세 함수를 정의해 둡니다. 잘 동작할 것입니다.^^
<?php
include "keystroke.php";
?>
<html>
<body>
<?php
beginKeyStroke();
addKeyStroke("h", "http://www.nzeo.com");
addKeyStroke("f", "http://www.firefox.org");
endKeyStroke();
?>
....
</body>
</html>
즉, 바디의 시작 부분에 keystroke를 정의해 줍니다.
keystroke.php->
function beginKeyStroke()
{
echo <<<MYHTMLSAFEOUTPUT
<SCRIPT LANGUAGE="JavaScript1.2">
var NS = (window.Event) ? 1 : 0
function checkKey(e) {
if (e == null) {
code = event.keyCode;
if(event.srcElement.tagName == "INPUT" || event.srcElement.tagName == "TEXTAREA") return true;
}
else {
if (e.altKey || e.ctrlKey) {
return true;
}
if(e.target.tagName == "INPUT" || e.target.tagName == "TEXTAREA") return;
code = e.which;
}
key = String.fromCharCode(code).toLowerCase();
if(code==13) key="enter";
var code = (NS) ? e.which : event.keyCode;
var key = String.fromCharCode(code);
for (var i = 0; i < ar.length; i++) {
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();
MYHTMLSAFEOUTPUT;
echo "n";
}
function addKeyStroke($key, $addr)
{
echo "ar[ar.length] = new hotKey("$key","$addr");n";
}
function endKeyStroke()
{
echo "</SCRIPT>";
}
세 함수를 정의해 둡니다. 잘 동작할 것입니다.^^
댓글 1
제목 | 글쓴이 | 날짜 |
---|---|---|
크롬리스(Chromless) 웹어플리케이션 -6 (최종) [4] | sundew | 2003.05.30 |
메뉴 옆에서 화살표가 스크롤되는.. [2] | 힘찬연못 | 2003.05.29 |
크롬리스(Chromless) 웹어플리케이션 -5 [3] | sundew | 2003.05.28 |
스크롤되는 레이어 나두 갖구 싶어서 ^^; 맹글어 봤습니다. [10] | M@xPond | 2003.05.28 |
오른쪽 버튼 클릭시 북마크창 띄우기(1석2조 방식) [4] | RedEye(rinja) | 2003.05.23 |
크롬리스(Chromless) 웹어플리케이션 -4 [4] | sundew | 2003.05.23 |
손님컴퓨터에 내홈피 즐겨찾기 원클릭으로추가시키기 [5] | 호호짱 | 2003.05.23 |
크롬리스(Chromless) 웹어플리케이션 -3 [5] | sundew | 2003.05.21 |
오늘 날짜와 시간 [3] | Brown | 2003.05.20 |
크롬리스(Chromless) 웹어플리케이션 -2 [5] | sundew | 2003.05.18 |
크롬리스(Chromless) 웹어플리케이션 -1 [1] | sundew | 2003.05.17 |
XXX는 객체가 아닙니다. [1] | RedEye | 2003.05.12 |
자바스크립트의 활용함에 대해.... [5] | RedEye | 2003.05.12 |
자바스크립트의 활용함에 대해 2 .... [1] | RedEye | 2003.05.18 |
[벅스 전용] 랜덤 음악 재생 Javascript. [1] | sundew | 2003.05.11 |
구문 오류 및 런타임 오류 모음 [1] | 아이쿠 | 2003.05.10 |
이벤트 핸들러 (Event Handler) 모음 [2] | 아이쿠 | 2003.05.10 |
랜덤 배경화면 구현하기 초간단 스크립트 공개(중복아님) [5] | 호호짱 | 2003.05.07 |
[배경음악] 첫곡은 랜덤, 그 이후로는 순차재생 [20] | 이주경 | 2003.05.06 |
[re] [소스] [배경음악] 첫곡은 랜덤, 그 이후로는 순차재생 --> 문제해결! [1] | 장진석 | 2003.06.02 |