使用 Greasemonkey 修改所有链接
我想修改一个网站的页面,该网站的所有链接都带有前缀“http://linkblur.com/? ”我尝试过这个:
links = getElementsByTagName('a');
for (l in links) {
l.href = l.href.replace('http://linkblur.com/?','');
}
但它不起作用。我做错了什么?
I want to mod a page from a site that prefixes all its links with "http://linkblur.com/?" I tried this:
links = getElementsByTagName('a');
for (l in links) {
l.href = l.href.replace('http://linkblur.com/?','');
}
But it doesn't work. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
Try:
迭代器迭代数组的所有属性,这些属性不是单个项目,而是
0
、1
、2
、 ...,n
,长度
。您想要更改迭代器,并且如果您想要为链接添加前缀,那么您也做错了。您当前正在执行的操作会将
linkblur.com...
替换为空字符串,即从现有链接中删除 linkblur。You for iterator iterates over all the properties of your array, which will not be the individual items, but rather,
0
,1
,2
, ...,n
,length
.You want to change your iterator, and if you want to prefix the links, you're doing that wrong, too. What you're currently doing will replace
linkblur.com...
with an empty string, i.e. remove linkblur from existing links.