[英]chrome extension to click a tag link
I'm trying to build an extension that will retrieve the tag link and if it matches a certain word the link would be clicked. 我正在尝试构建将检索标签链接的扩展,如果它与某个单词匹配,则将单击该链接。 The only problem is I can't use the click() method because the a tag does not contain an id or class name.
唯一的问题是我不能使用click()方法,因为标记不包含ID或类名。 How would I go about clicking the link or just to redirect chrome to go to the link?
我该如何点击链接或仅重定向chrome转到链接?
you can try something like this in your content script 您可以在内容脚本中尝试类似的操作
var links = document.getElementsByTagName('A');
for (var i=0; i<links.length; i++) {
if (links[i].href.indexOf('certain_word') > -1) links[i].click();
break;
}
window.location = "http://www.google.com";
window.location works fine. window.location工作正常。 Just pass the href value when you find the matched content
找到匹配的内容时只需传递href值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.