I have one SharePoint-hosted app in which I am fetching all the Site Collection list from tenant using REST api call using following snippet:

var spAppWebUrl = _spPageContextInfo.siteAbsoluteUrl;
var queryUrl = spAppWebUrl + "/_api/search/query?querytext='contentclass:sts_site'";

   url: queryUrl + "'contentclass:sts_site'",
   headers: { "Accept": "application/json; odata=verbose" },
   contentType: "application/json; odata=verbose",
   success: function (sitedata) {
       // Parsing the sitedata object and getting the site collection url
       // Using url I am giving the SRC of an iframe to show the preview of the site collection.
       jQuery('results').append('<iframe src="' + url + '" name="previewFrame" id="previewFrame"></iframe>');

As explained in code, I am using the Site Collection URL. I am running the app on following domain: https://myo365domain.sharepoint.com/_layouts/15/start.aspx#/default.aspx. On Page Load I request for result of all site collection list and hover over that item, I am showing preview in iframe like search results (like out of the box preview feature). But when I see the chrome browser's console I see following error:

Refused to display 'https://myo365domain-my.sharepoint.com/personal/myo365admin_onmicrosoft_com/_layouts/15/start.aspx#/default.aspx' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

Note: I have full access given for tenant in my SharePoint hosted app. This error occurs only when the domain is different. So I have referred this and this articles, but couldn't identify the issue. I am only showing preview of the result site collection in iframe. Does anyone know any workaround for this? Any help would be much appreciated.

Your Answer

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

Browse other questions tagged or ask your own question.