3

When SharePoint Add in installed I want to add javascript on site master page in which app was installed pro grammatically in Office 365 SharePoint Online.

How to do that dynamically?

0

It is not possible in SharePoint hosted app because in SharePoint Hosted app, we don't have App installed or uninstalled event receiver.

For SharePoint Hosted app, we need to give one configuration page and on configuration page we need to write below custom code to insert javascript into Site master page.

//provisionScriptLink: method that adds the custom action
    var provisionScriptLink = function () {
        var context;
        var factory;
        var appContextSite;
        var folder;
        context = new SP.ClientContext(decodeURIComponent(getQueryStringParameter('SPAppWebUrl')));
        factory = new SP.ProxyWebRequestExecutorFactory(decodeURIComponent(getQueryStringParameter('SPAppWebUrl')));
        context.set_webRequestExecutorFactory(factory);
        appContextSite = new SP.AppContextSite(context, decodeURIComponent(getQueryStringParameter('SPHostUrl')));



        var actions = appContextSite.get_site().get_userCustomActions();
        context.load(actions);
        context.executeQueryAsync(function () {
            var enumerator = actions.getEnumerator();


            var newAction = actions.add();
            // the 'description' is what we'll use to uniquely identify our custom action
            newAction.set_description("CustomActionTag");
            newAction.set_location('ScriptLink');
            newAction.set_scriptBlock(inject());
            newAction.set_sequence(1000);
            newAction.update();


            context.executeQueryAsync(function () {
              console.log('successfully added');

            }, function(){
console.log('failed');
}
              );
        }, function(){
console.log('failed');
});
    };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.