 |
|
|  |
|
 홈페이지 |
21년 전 |
Firefox및 IE에서 모두 동작하는 방법으로 php를 써서 재사용하기 쉽게 고쳐봤습니다. html에서 h키를 누르면 www.dajuji.com이 뜨는 소스.
<?php
include "keystroke.php";
?>
<html>
<body>
<?php
beginKeyStroke();
addKeyStroke("h", "http://www.xtx.kr");
addKeyStroke("f", "http://trot.xtx.kr");
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>";
}
세 함수를 정의해 둡니다. 잘 동작할 것입니다.^^ |
|
추천 : 457 |
추천
목록
|
|
|  |
|