2

I have a provider-hosted, on-premise app using SharePoint 2013.

The Chrome control works fine when first accessing the app from SharePoint, however, on subsequent pages, the chrome control does not work.

I figured that since my links within the application would not all have the SPHostUrl or SPAppWebURl in the query string parameters, I would store them in a cookie for use on subsequent pages. This much works, in both cases I get the script url of http://{hostWeb}/_layouts/15/SP.UI.Controls.js

However, when I try to apply the chrome control with the code:

var sharepointScript = sharepointHostWebUrl + "/_layouts/15/SP.UI.Controls.js";

$.getScript(sharepointScript, function () {
    var options = {
        "appIconUrl": "/Content/images/AppIcon.png",
        "appTitle": appTitle,
        "settingsLinks": [
            {
                "linkUrl": "http://www.google.com",
                "displayName": "Google"
            },
            {
                "linkUrl": "http://www.microsoft.com",
                "displayName" : "Microsoft"
            }
        ]
    };

    var nav = new SP.UI.Controls.Navigation("Chrome", options);
    nav.setVisible(true);
});

then the initial page from SharePoint works, but subsequent pages get the JavaScript error:

Error: Error: The app's host site url is not set.
Source File: http://{hostweb}/_layouts/15/SP.UI.Controls.js?_=1369967456299
Line: 2

I also tried changing to AppWeb instead of hostWeb, but got the same results.

How can I make the Chrome control work on subsequent pages?

4

Getting the chrome control depends on the query parameters passed to your page, so you need to add these to all internal links something like:

"linkUrl": "page2.html?"
        + document.URL.split("?")[1],

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.