【发布时间】:2015-02-19 16:14:57
【问题描述】:
我正在构建一个页面,该页面需要能够获取网页上的所有文件链接并将它们添加到下拉列表中。原来是脚本应该与文件在同一页面上,但现在它需要搜索外部。这是我改之前用的
<script>
$(document).ready(function() {
var arr = [];
var filenames = [];
var alt_var;
var baseURL = "www.fakeurl.com"
$('.ms-vb-icon').find('a').each(function(){
var temp = $(this).attr('href')
$(this).find('img').each(function(){
alt_var = $(this).attr('alt');
});
if(temp.indexOf('.csv') != -1){arr.push(temp); filenames.push(alt_var);}
});
for(i = 0; i < arr.length; ++i)
{
var x = document.createElement('li');
var a = document.createElement('a');
var t = document.createTextNode(" " + filenames[i]);
var fullURL = baseURL + arr[i];
a.setAttribute('href',"#");
a.setAttribute('class', "glyphicon glyphicon-file");
a.setAttribute('id', baseURL + arr[i]);
a.setAttribute('onclick', "drawChart(this.id)");
a.appendChild(t);
x.appendChild(a);
document.getElementById("dropdownfiles").appendChild(x);
}
});
</script>
如何更改它以搜索外部 URL。 (PS Javascript 新手)
【问题讨论】:
-
“外部”URL 是否在同一个域中?
-
很可能,但它会在公司共享点站点上,所以我希望它可以连接到所有不同的共享点域
标签: javascript html file url dom