You are here: irt.org | FAQ | JavaScript | Image | Q273 [ previous next ]
This will work as required in Netscape Navigator 4 and Internet Explorer 4:
<HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"><!-- function y2k(number) { return (number < 1000) ? number + 1900 : number; } function checkFirst(url) { location.href = url; } //--></SCRIPT> <SCRIPT LANGUAGE="JavaScript1.2"><!-- var when = new Date(); var what = ''; function netscapeKeyPress(e) { if (e.modifiers == 2) { // Ctrl key pressed when = new Date(); what = 'Ctrl'; } } function microsoftKeyPress() { if (window.event.ctrlKey) { // Ctrl key pressed when = new Date(); what = 'Ctrl'; } } if (navigator.appName == 'Netscape') { window.captureEvents(Event.KEYPRESS); window.onKeyPress = netscapeKeyPress; } function checkFirst(url) { var now = new Date(); var difference = Date.UTC(y2k(now.getYear()),now.getMonth(),now.getDate(),now.getHours(),now.getMinutes(),now.getSeconds()) - Date.UTC(y2k(when.getYear()),when.getMonth(),when.getDate(),when.getHours(),when.getMinutes(),when.getSeconds()); if (difference < 1000) location.href = url; } //--></SCRIPT> </HEAD> <BODY onKeyPress="microsoftKeyPress()"> <A HREF="javascript:checkFirst()"><IMG SRC="picture.gif" WIDTH="100" HEIGHT="100" BORDER="0"></A> </BODY> </HTML>