Using Keyboard Shortcuts in Javascript

New type of web sites use keyboards for some functions. It is always helping more usable. I hope this codes will help your web site.

In the following example, we’re simply going to verify the key pressed down by the user. If the key pressed are Ctrl+S, a function will be triggered.

var isCtrl = false;
document.onkeyup=function(e) {
    if(e.which == 17) isCtrl=false;
}document.onkeydown=function(e){
    if(e.which == 17) isCtrl=true;
    if(e.which == 83 && isCtrl == true) {
         alert('Keyboard shortcuts are cool!');
         return false;
    }
}

Example with the JQuery framework

var isCtrl = false;$(document).keyup(function (e) {
if(e.which == 17) isCtrl=false;
}).keydown(function (e) {
    if(e.which == 17) isCtrl=true;
    if(e.which == 83 && isCtrl == true) {
        alert('Keyboard shortcuts + JQuery are even more cool!');
return false;
}
});

For more and keyboard shorcuts codes click here>

Countdown Date & Time JavaScript

I need javascript to countdown a date but with time. I search a lot and find a solution. Here it is :)

You can use in your HTML file:

Dont worry! Only <script language="JavaScript">
TargetDate = "6/11/2010 1:00";
BackColor = "white";
ForeColor = "navy";
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = "%%D%% Day, %%H%% Hour, %%M%% Minute, %%S%% Second ";
FinishMessage = "World cup start..";
</script>
<script language="JavaScript" src="countdown.js"></script> left to begin World Cup 2010.