Link onclick - do something before following href

▼魔方 西西 提交于 2020-01-24 16:41:17

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/5368008/link-onclick-do-something-before-following-href

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!