Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q273 Is it possible to have an image which is not an active link unless the ctrl key is depressed when clicking?

irt.org | Knowledge Base | JavaScript | Image | Q273 [ previous next ]

Q273 Is it possible to have an image which is not an active link unless the ctrl key is depressed when clicking?

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.