我正在构建一个应该显示有关特定人员信息的Sharepoint 2013应用程序部分。人GUID将通过Sharepoint页面URL中的querystring提供,并以某种方式将querystring(键/值)传递给所有iFrame/app部分。使用Sharepoint查询字符串值作为应用程序部分属性
起初我希望能够使用App部件的Element.xml文件中的自定义属性将查询字符串发送到iFrame(我期望Sharepoint足够聪明,它有一个datatype = querystirng,它从SP抓取查询字符串URL并将其推送到应用程序部分)。但是Elements.xml中的属性似乎是静态的,只能在编辑SP页面时在“编辑Web部件”菜单中定义。
我试图通过使用JavaScript(按照本指南,修改一下位:http://prasantabarik.wordpress.com/2013/09/26/pass-querystring-value-from-sharepoint-page-to-app-partclient-web-part/)将查询字符串注入到Sharepoint页面中包含的所有iframe中。即我打开所有的iframe,并更改了iframe.src(也尝试过iframe.setAttribute(src,newSrc)),以包含JavaScript从windows.location.search中抓取的querystrings。这似乎工作80%的时间,页面与应用程序部分加载与查询字符串传递到所有应用程序部分成功加载。然而,其他20%的时间iframe.src设置正确,但没有被浏览器重新加载(显示没有查询字符串的初始应用程序部分页面)。这似乎是我的Chrome v.31浏览器中的一个问题。在IE中它每次都能成功运行。
这里是我的SharePoint的代码片段托管的JavaScript(包含在在SharePoint主模板的底部):
var sharepointQueryKeyValuePairs = {};
window.location.search.substr(1).split("&").forEach(function (pair) {
if (pair === "") return;
var parts = pair.split("=");
sharepointQueryKeyValuePairs[parts[0]] = parts[1];
});
var arrFrames = document.getElementsByTagName("iframe");
for (var i = 0; i < arrFrames.length; i++) {
var iFrame = arrFrames[i];
var clientID = encodeURIComponent("displayMode=spRedirect");
if (iFrame.src.indexOf(clientID) != -1) {
var querystring = encodeURIComponent("displayMode=sp");
var newIframeSrc = iFrame.src.replace(clientID, querystring);
var sharepointQueryKeyValuePairsCopy = {};
$.extend(sharepointQueryKeyValuePairsCopy, sharepointQueryKeyValuePairs);
newIframeSrc.split(encodeURIComponent('?'))[1].split(encodeURIComponent("&")).forEach(function (pair) {
if (pair === "") return;
var parts = pair.split(encodeURIComponent("="));
if (sharepointQueryKeyValuePairs.hasOwnProperty(parts[0])) {
newIframeSrc = newIframeSrc.replace(encodeURIComponent(parts[0] + "=" + parts[1]), encodeURIComponent(parts[0] + "=" + sharepointQueryKeyValuePairs[parts[0]]));
delete sharepointQueryKeyValuePairsCopy[parts[0]];
}
});
//todo: loop through sharepointQueryKeyValuePairsCopy and inject the rest of the querystring values
iFrame.setAttribute('src', newIframeSrc);
//also tried iFrame.src = newIframeSrc;
}
}
有没有人对如何这可能是工作的任何想法?最好有一个更简洁的解决方案的建议。我不喜欢javascript解决方案,应该有另一种更优雅的方式将SP查询字符串传递给应用程序部分!
问题以前在这里问(https://sharepoint.stackexchange.com/questions/72189/use-query-string-value-as-app-part-property-2013)没有任何答案,所以我试试我的运气。
感谢尼古拉,这可能是答案,为什么我的JS在IE和FF,而不是Chrome浏览器...但是,我希望有另一种解决我的问题,它不需要JS “黑客”。 – Howie