【发布时间】:2017-12-14 14:19:45
【问题描述】:
我在 SharePoint 2010 中有一个文档库,该库将保存不同类型的文件:Word、Excel、PDF、HTML...
大多数文件类型在应用程序中打开。那些没有的,如 .htm 通讯,在同一个窗口中打开。 Sharepoint 文档库链接到文件,但不允许设置目标属性。
我想以编程方式设置这个 onload。
我已经开始尝试编写代码了:
for(var i = 0, l=document.links.length; i<l; i++) {
var id = document.links[i].href;
var idl = id.length;
if(idl >=7 ){
var lastfour = id.substr(id.length - 4);
var lastfive = id.substr(id.length - 5);
if (lastfour == ".pdf"){
//alert(document.links[i].href);
document.links[i].setAttribute('target', '_blank');
document.links[i].setAttribute('onfocus', 'return flase;');
}
if (lastfour == ".htm"){
//alert(document.links[i].href);
document.links[i].setAttribute('target', '_blank');
document.links[i].setAttribute('onfocus', 'return false;');
}
if (lastfive == ".html"){
//alert(document.links[i].href);
document.links[i].setAttribute('target', '_blank');
document.links[i].setAttribute('onfocus', 'return false;');
}
}
}
这是有效的,因为它会导致链接在新窗口中打开,但也会在主窗口中打开。经过进一步研究,我发现 SharePoint 对链接做了一些古怪的事情:
<a onfocus="OnLink(this)" href="/Diocesan/2017 Diocesan Special Collection Calendar.pdf" onmousedown="return VerifyHref(this,event,'0','PdfFile.OpenDocuments','')" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','','0','PdfFile.OpenDocuments','','','','1210','0','0','0x400001f07fbf1bff','','')">2017 Diocesan Special Collection Calendar</a>
我认为我的问题是由于设置了 onfocus 属性或者可能是 onclick。我不确定发生了什么。我应该尝试设置 onmousedown、onclick 和 onfocus = "" 吗?
【问题讨论】:
标签: jquery sharepoint