Skip to content
Loading
  
  •       
  •   
  •   
  •  
    0
  • Nanddeep Nachan
    0
    Tried this code on my environment and it does not display whole SharePoint site in an iframe.
    Do you have any additional script running on the site?  
    0
  • 0
    Hi Nandeep, 
                          I think it inherits the master page that was the issue.I am facing another issue i can't take app weburl and host web url in the below code.Can you help me in it.the below one is updated code,but i got _spPageContextInfo undefined error.
     
    1. <%@ Page Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Language="C#" %>  
    2.   
    3. <%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
    4. <%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
    5. <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
    6.   
    7. "AllowFraming" runat="server" />  
    8.   
    9.   
    10.   
    11.     "../../Content/App.css" rel="stylesheet" />  
    12.     "../Scripts/jquery-1.9.1.min.js">  
    13.     "text/javascript" src="https://ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js">  
    14.     "text/javascript" src="/_layouts/15/init.js">  
    15.     "text/javascript" src="/_layouts/15/sp.runtime.js">  
    16.     "text/javascript" src="/_layouts/15/sp.js">  
    17.   
    18.     "text/css">  
    19.         #tabledocuments th {  
    20.             text-align: center;  
    21.             border: 1.5px solid #eae8e8;  
    22.             border-collapse: collapse;  
    23.             font-size: 14px;  
    24.         }  
    25.   
    26.         #tabledocuments td {  
    27.             text-align: center;  
    28.             border: 1.5px solid #eae8e8;  
    29.             border-collapse: collapse;  
    30.             font-size: 14px;  
    31.         }  
    32.   
    33.         #tableSubsites th {  
    34.             text-align: center;  
    35.             border: 1.5px solid #eae8e8;  
    36.             border-collapse: collapse;  
    37.             font-size: 14px;  
    38.         }  
    39.   
    40.         #tableSubsites td {  
    41.             text-align: center;  
    42.             border: 1.5px solid #eae8e8;  
    43.             border-collapse: collapse;  
    44.             font-size: 14px;  
    45.         }  
    46.       
    47.     "text/javascript">  
    48.         var hostweburl;  
    49.         var appweburl;  
    50.         $(document).ready(function () {  
    51.             debugger;  
    52.             SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {  
    53.                 debugger;  
    54.   
    55.   
    56.                 //Get the URI decoded URLs.  
    57.                 hostweburl = _spPageContextInfo.siteAbsoluteUrl;  
    58.                 appweburl = _spPageContextInfo.webAbsoluteUrl;  
    59.                 if (_spPageContextInfo.siteAbsoluteUrl.indexOf('-') > -1);  
    60.                 {  
    61.                     var hypenIndex = _spPageContextInfo.siteAbsoluteUrl.indexOf('-');  
    62.                     var periodIndex = _spPageContextInfo.siteAbsoluteUrl.indexOf('.');  
    63.                     var removeStr = _spPageContextInfo.siteAbsoluteUrl.substring(hypenIndex, periodIndex);  
    64.                     hostweburl = _spPageContextInfo.siteAbsoluteUrl.replace(removeStr, '');  
    65.                 }  
    66.   
    67.                 // resources are in URLs in the form:  
    68.                 // web_url/_layouts/15/resource  
    69.                 var scriptbase = hostweburl + "/_layouts/15/";  
    70.                 // Load the js files and continue to the successHandler  
    71.                 $.getScript(scriptbase + "SP.RequestExecutor.js", getListsFromRootSite);  
    72.                 ResizeIFrame();  
    73.             });  
    74.   
    75.         });  
    76.   
    77.   
    78.   
    79.         function ResizeIFrame() {  
    80.             if (window.parent == null)  
    81.                 return;  
    82.             var senderId = $("#RequestContext_SenderId").val();  
    83.             var height = $("#form1").height();  
    84.             var width = $("#form1").width();  
    85.             var message = " + senderId + " >"  
    86.             + "resize(" + width + "," + height + ")";  
    87.             window.parent.postMessage(message, document.referrer);  
    88.         }  
    89.   
    90.         function getListsFromRootSite() {  
    91.             try {  
    92.                 debugger;  
    93.                 //SP.AppContextSite('" + hostweburl + "')/  
    94.                 var executor = new SP.RequestExecutor(appweburl);  
    95.                 console.log(appweburl + "/_api/SP.AppContextSite(@target)/Web/lists?@target='" + hostweburl + "'&$filter=BaseTemplate eq 101&$expand=RootFolder");  
    96.                 executor.executeAsync(  
    97.                 {  
    98.                     url: appweburl + "/_api/SP.AppContextSite(@target)/Web/lists?$filter=BaseTemplate eq 101&$expand=RootFolder&@target='" + hostweburl + "'",  
    99.                     method: "GET",  
    100.                     headers: {  
    101.                         "Accept": "application/json; odata=verbose"  
    102.                     },  
    103.                     async: false,  
    104.                     success: SuccessHandler,  
    105.                     error: errorTitleHandlerXD  
    106.                 });  
    107.                 //)  
    108.             } catch (e) {  
    109.                 console.log(e);  
    110.             }  
    111.         }  
    112.   
    113.         function SuccessHandler(data) {  
    114.             try {  
    115.   
    116.                 debugger;  
    117.                 var jsonObject = JSON.parse(data.body);  
    118.                 var lists = jsonObject.d.results;  
    119.                 //var lists = data.d.results;  
    120.                 var tempValue = "General Folders

      "
      ;  
    121.                 tempValue += "";  
    122.                 lists.forEach(function (list) {  
    123.                     var itemCount = getDocumentLibrariesItemsCount(hostweburl, list.Title);  
    124.                     if (!window.location.origin) {  
    125.                         window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');  
    126.                     }  
    127.                     var libraryURL = window.location.origin + list.RootFolder.ServerRelativeUrl;  
    128.                     console.log("Document URL= " + libraryURL);  
    129.                     tempValue += " + libraryURL + "'>" + list.Title + " (" + itemCount + ")";  
    130.                 });  
    131.                 tempValue += "";  
    132.                 $("#divRootSiteLibraries").html(tempValue);  
    133.                 getSubsites();  
    134.   
    135.   
    136.             } catch (e) {  
    137.   
    138.             }  
    139.         }  
    140.   
    141.         //Error with Title.  
    142.         function errorTitleHandlerXD(data, errorCode, errorMessage) {  
    143.             console.log("Could not complete cross-domain call: " + errorMessage);  
    144.             console.log(JSON.stringify(data));  
    145.         }  
    146.   
    147.         function getDocumentLibrariesItemsCount(webURL, listTitle) {  
    148.             var itemCount;  
    149.             try {  
    150.                 debugger  
    151.                 jQuery.ajax({  
    152.                     url: appweburl + "/_api/SP.AppContextSite(@target)/Web/lists/getByTitle('" + listTitle + "')?$select=ItemCount&@target='" + webURL + "'",  
    153.                     method: "GET",  
    154.                     headers: {  
    155.                         "Accept": "application/json; odata=verbose"  
    156.                     },  
    157.                     async: false,  
    158.                     success: function (data) {  
    159.                         debugger  
    160.                         itemCount = data.d.ItemCount;  
    161.                     },  
    162.                     error: function (data) {  
    163.                         console.log(data);  
    164.                     }  
    165.                 });  
    166.                 return itemCount;  
    167.             }  
    168.             catch (e) {  
    169.                 console.log(e);  
    170.             }  
    171.         }  
    172.   
    173.         function getDocumentLibrariesCount(webURL) {  
    174.             var libraryCount;  
    175.             try {  
    176.                 jQuery.ajax({  
    177.                     url: webURL + "/_api/SP.AppContextSite(@target)/Web/lists?$filter=BaseTemplate eq 101&@target='" + webURL + "'",  
    178.                     method: "GET",  
    179.                     headers: {  
    180.                         "Accept": "application/json; odata=verbose"  
    181.                     },  
    182.                     async: false,  
    183.                     success: function (data) {  
    184.                         debugger  
    185.                         libraryCount = data.d.results.length;  
    186.                     },  
    187.                     error: function (data) {  
    188.                         console.log(data);  
    189.                     }  
    190.                 });  
    191.                 return libraryCount;  
    192.             }  
    193.             catch (e) {  
    194.                 console.log(e);  
    195.             }  
    196.         }  
    197.   
    198.         function getSubsites() {  
    199.             try {  
    200.                 jQuery.ajax({  
    201.                     url: appweburl + "/_api/SP.AppContextSite(@target)/Web/GetSubwebsFilteredForCurrentUser(nWebTemplateFilter=-1)?$filter=WebTemplate ne 'APP'&@target='" + hostweburl + "'",  
    202.                     method: "GET",  
    203.                     headers: {  
    204.                         "Accept": "application/json; odata=verbose"  
    205.                     },  
    206.                     async: false,  
    207.                     success: function (data) {  
    208.                         var icount = 1;  
    209.                         var subSites = data.d.results;  
    210.                         console.log(subSites);  
    211.                         var tempValue = "Management Lines

      "
      ;  
    212.                         tempValue += "";  
    213.                         subSites.forEach(function (site) {  
    214.                             debugger;  
    215.                             if (!window.location.origin) {  
    216.                                 window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');  
    217.                             }  
    218.                             var webURL = window.location.origin + site.ServerRelativeUrl;  
    219.                             var librariesCount = getDocumentLibrariesCount(webURL);  
    220.                             if (icount == 1)  
    221.                                 tempValue += "";  
    222.                             tempValue += "" +  
    223.                                 "" + site.Title + "";  
    224.                             tempValue += " + webURL + "'>Active Issuers (" + librariesCount + ")";  
    225.                             var remainder = icount % 4;  
    226.                             if (remainder == 0)  
    227.                                 tempValue += "";  
    228.                             icount++;  
    229.                         });  
    230.                         tempValue += "";  
    231.                         $("#divSubSites").html(tempValue);  
    232.                     },  
    233.                     error: function (data) {  
    234.                         console.log(data);  
    235.                     }  
    236.                 });  
    237.             } catch (e) {  
    238.                 console.log(e);  
    239.             }  
    240.         }  
    241.   
    242.         // Function to retrieve a query string value.  
    243.         // For production purposes you may want to use  
    244.         //  a library to handle the query string.  
    245.         function getQueryStringParameter(paramToRetrieve) {  
    246.             var params =  
    247.                 document.URL.split("?")[1].split("&");  
    248.             var strParams = "";  
    249.             for (var i = 0; i < params.length; i = i + 1) {  
    250.                 var singleParam = params[i].split("=");  
    251.                 if (singleParam[0] == paramToRetrieve)  
    252.                     return singleParam[1];  
    253.             }  
    254.         }  
    255.       
    256.   
    257.   
    258.     "display: inline-block;">  
    259.         "divRootSiteLibraries" style="display: inline-block; vertical-align: top;">
      
  •         "divSubSites" style="display: inline-block; vertical-align: top;">  
  •       
  •   
  •   
  •  
    0
  • Nanddeep Nachan
    0
    Please use below sample code
    1. var context;  
    2. var web;  
    3. var spHostUrl;  
    4. var parentContext  
    5.   
    6. spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));  
    7. context = new SP.ClientContext.get_current();  
    8. parentContext = new SP.AppContextSite(context, spHostUrl);  
    9. web = parentContext.get_web();  
    10. var list = web.get_lists().getByTitle("My List"));  
     
    0
  • 0
    Hi nandeep,
     
    I am not getting value for decodeURIComponent(getQueryStringParameter('SPHostUrl')); since the app is loading in iframe.did i missing anything?
    0
  • 0
    Hi nandeep,
                        I fixed the issue with sending standard params in elements.xml file i missed that before.thanks a lot for your responses.
     
    1. "html" Src="~appWebUrl/Pages/RootsiteWebpart.aspx?{StandardTokens}" />  
     
    0