如果在页面上找到部分匹配的URL,请获取该URL

时间:2014-06-14 07:03:07

标签: javascript google-chrome-extension

我目前正在创建Chrome扩展程序, 并希望获得页面上以“https://google.com”开头的任何网址。

感谢。

1 个答案:

答案 0 :(得分:1)

以下内容在文档中创建以“https://google.com

开头的网址列表
var checkRE = new RegExp('^https://google.com');
var list = []
for (var i = 0; i < document.links.length; i++) {
    if(checkRE.test(document.links[i].href)) {
        list.push(document.links[i].href)
    }
}
console.log(list);