nestalgia
nestalgia

Reputation: 60

Link onclick - do something before following href

How do I tell firefox browser to do something with a link(etc string trim) that i have just clicked then go to the modified link?

Is is possible ? or is there an addon for this?

Upvotes: 2

Views: 2790

Answers (1)

Felix Kling
Felix Kling

Reputation: 816282

You don't need to create a plugin for that. This can be done with a simple script and Greasemonkey.

It is also not necessary to add a click handler to every link. It is better to use event delegation:

document.addEventListener('click', function(event) {
    if(event.target.nodeName === 'A') {
        var href = event.target.href;
        // change the URL
        location.href = href;
        event.preventDefault();
    } 
}, true);

Upvotes: 4

Related Questions