链接onclick - 按照href之前做一些事情 [英] Link onclick - do something before following href

查看:133
本文介绍了链接onclick - 按照href之前做一些事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何告诉firefox浏览器做一些链接(等字符串修剪),我刚刚点击,然后去修改后的链接?



是可能的?或者有没有插件呢?

解决方案

您不需要为此创建插件。这可以通过一个简单的脚本和 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆