Q:

after a few seconds an image has been clicked, open a link

I have already tried a lot, but did not come to an optimal solution. I have an image (html) and would like that if you press/click the image 5 seconds long, that he opens a link.
So far I have this code:
if (...) { window.location.href = 'http://www.google.com'; }

http://jsfiddle.net/xBz5k/

A:

All the other answers open the link 5 seconds after a simple click. This one opens the link if the click lasted 5 seconds:
// the gif
var imgAnimation = '/images/animation.gif';
// the original image
var imgInitial = '/images/still.jpg';
// preload the gif
(new Image()).src = imgAnimation;
var imageMouseDown;
// mouse button gets pressed
$('#image').mousedown(function() {
    $(this).prop('src', imgAnimation);
    // start the timeout
    imageMouseDown = setTimeout(function() {
        window.location.href = 'http://www.google.com';
    }, 5000);
});

// when the mouse button gets released
$('#image').mouseup(function() {
    // the timeout isn't fired yet -> clear it
    if (imageMouseDown) {
            // set the old image again
            $(this).prop('src', imgStill);
        clearTimeout(imageMouseDown);
    }
});

Here's a demo including the changing image: http://jsfiddle.net/7Qugn/

