Passing querystring arguments to a Office 365 word add-in

无人久伴 提交于 2019-12-12 01:25:37

问题


Is there any support in the Office API to pass arguments to an office add-in? When a word document is opened in Office 365 by clicking on the document 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

Can we pass some querystrings in the URL which is accessible in the add-in environment?


回答1:


Yes, you can. You could refer to the following code:

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, ' '));  
}

Call:

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

You could refer to the following link:

How can I get query string values in JavaScript?



来源:https://stackoverflow.com/questions/53222788/passing-querystring-arguments-to-a-office-365-word-add-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!