简体   繁体   English

Chrome扩展程序:点击后更改链接的网址

[英]Chrome extension: Change URL of links when clicked

I'm trying to make a Chrome extension which changes the URLs pointed to by certain links posted on Facebook. 我正在尝试制作一个Chrome扩展程序,用于更改Facebook上发布的某些链接指向的网址。 At first I thought of doing a simple regex search and substitution in $(document).ready() , but Facebook loads a lot of home screen content dynamically, so a lot of stuff will be left out. 起初我想在$(document).ready()中进行简单的正则表达式搜索和替换,但Facebook会动态加载大量主屏幕内容,因此很多东西都会被遗漏。 I then wrote this method: 然后我写了这个方法:

$('a').click(function () {
    console.log(this.href);
}

...and I can then do matching etc on this.href the question is, how do I change the destination of the link when the user clicks on it? ...然后我可以在this.href上进行匹配等问题,当用户点击它时,如何更改链接的目的地?

$('a').click(function(){
    $(this).attr('href', yourdestination);
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM