开发者

Link onclick - do something before following href

开发者 https://www.devze.com 2023-02-18 03:18 出处:网络
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?

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?


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消