Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   HTML/DHTML/CSS/JS/VB (http://www.flasher.ru/forum/forumdisplay.php?f=66)
-   -   создание горячих клавиш на JS (http://www.flasher.ru/forum/showthread.php?t=77092)

buka2 17.03.2006 22:37

создание горячих клавиш на JS
 
как сделать, чтобы при нажатии на определенную клавишу (комбинацию клавиш) запускалась конкретная функция?

KidsKilla 18.03.2006 15:21

код с яндекса:
Код:

function init() {
        if (self.parent.frames.length != 0) {
                self.parent.location = document.location;
        }
        if (document.getElementById) {
                document.onkeydown = register;
                if (document.forms['web'].text) {
                        document.forms['web'].text.onfocus = function () {
                        searchInputIsActive = true;
                        if (document.forms['web'].text.select && CtrlUp) {document.forms['web'].text.select();}
                    };
                        document.forms['web'].text.onblur = function () {searchInputIsActive = false; CtrlUp = false;};
                        queryString = document.forms['web'].text.value;
                }
        }
}

function register(e) {
        var code;
        if (!e) var e = window.event;
        if (e.keyCode) code = e.keyCode;
        else if (e.which) code = e.which;


        if ((code == 13) && (e.ctrlKey == true)) document.forms['web'].submit();

        if (!searchInputIsActive) {
                if ((code == 37) && (e.ctrlKey == true)) {
                        var destination = document.getElementById('previous_page');
                        if (destination) {
                                r(destination, 'stred/pid=1/cid=51');
                                location.href = destination.href;
                        }
                }
                if ((code == 39) && (e.ctrlKey == true)) {
                        var destination = document.getElementById('next_page');
                        if (destination) {
                                r(destination, 'stred/pid=1/cid=50');
                                location.href = destination.href;
                        }
                }
        }
        if ((code == 38) && (e.ctrlKey == true) && document.forms['web'].text) {
                CtrlUp = true;
                r(location, 'stred/pid=1/cid=52');
                document.forms['web'].text.focus();
        }
}



Часовой пояс GMT +4, время: 01:08.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.