将querystring参数传递到Office 365单词加载项

时间:2018-11-09 09:13:30

标签: office365 office-js office-addins

Office API是否支持将参数传递给Office加载项?通过单击文档URL在Office 365中打开Word文档时

https://username-my.sharepoint.com/:w:/r/personal/username_tenantname_onmicrosoft_com/_layouts/15/Doc.aspx?sourcedoc=%7QAF15650B-72D2-447C-BE9C-9201A7F61BA4%7D&file=Document%20158.docx&action=default&mobileredirect=true

我们可以在外接程序环境中访问的URL中传递一些查询字符串吗?

1 个答案:

答案 0 :(得分:0)

是的,可以。您可以参考以下代码:

function getParameterByName(name, url) {
    // This URL is written directly, you could replace it with your variable.
    if (!url) url = "https://username-my.sharepoint.com/:w:/r/personal/username_tenantname_onmicrosoft_com/_layouts/15/Doc.aspx?sourcedoc=%7QAF15650B-72D2-447C-BE9C-9201A7F61BA4%7D&file=Document%20158.docx&action=default&mobileredirect=true";
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));  
}

致电:

var sourcedoc = getParameterByName('sourcedoc');
var file = getParameterByName('file');
var action = getParameterByName('action');
var mobileredirect = getParameterByName('mobileredirect');

您可以参考以下链接:

How can I get query string values in JavaScript?