链接onclick - 按照href之前做一些事情 [英] Link onclick - do something before following href
本文介绍了链接onclick - 按照href之前做一些事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是可能的?或者有没有插件呢?
解决方案
您不需要为此创建插件。这可以通过一个简单的脚本和 Greasemonkey 。
不需要为每个链接添加点击处理程序。最好使用事件委托:
document.addEventListener('click',function ){
if(event.target.nodeName ==='A'){
var href = event.target.href;
//改变URL
location.href = href;
event.preventDefault();
}
},true);
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);
这篇关于链接onclick - 按照href之前做一些事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文