none
share point office 365 Get global navigation setting value in javascript file

    Question

  • We have developed an internal portal with multiple subsites using sharepoint office 365. We created our own page layouts/masterpage for the sites and most of the things like menu's, page body and page logos are customized(unique for all sites/subsites).

    Each page has a header logo and a url assigned to that logo(logo describes site or subsite name). We have written a javascript file to load these logo and url and calling on the masterpage. Now the problem is these logo and link should load based on Global navigation

    Example: If the site is using the same navigation items as the parent site?

    • Yes - pull logo and link from site above
    • No - pull logo and link according to site name

    if i get the GlobalNavigation setting value then i can do this in javscript file. Is there a way to get this GlobalNavigation setting value in javascipt file? I googled on this but didn't get enough information.

    Thanks in advance,

    Amarnath

    Monday, January 30, 2017 11:16 AM

Answers

  • Hi Amarnath,

    We can use REST API to get this value.

    /_api/web/Navigation/UseShared

    Check the UseShared is true or false. The following code for your reference:

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){
    	console.log(isUseShared());
    });
    function isUseShared(){
    	 var useShared=false;	 
    	 var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/Navigation/UseShared";
    	 $.ajax({
    		 url: url,
    		 method: "GET",
    		 headers: { "Accept": "application/json; odata=verbose" },
    		 async: false,
    		 success: function (data) {
    		 	useShared=data.d.UseShared;
    		 },
    		 error: function (data) {
    		 }
    	 });
    	return useShared;
    }
    </script>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by AmarnathBabu Tuesday, January 31, 2017 10:29 AM
    Tuesday, January 31, 2017 6:15 AM
    Moderator

All replies

  • Hi Amarnath,

    We can use REST API to get this value.

    /_api/web/Navigation/UseShared

    Check the UseShared is true or false. The following code for your reference:

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){
    	console.log(isUseShared());
    });
    function isUseShared(){
    	 var useShared=false;	 
    	 var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/Navigation/UseShared";
    	 $.ajax({
    		 url: url,
    		 method: "GET",
    		 headers: { "Accept": "application/json; odata=verbose" },
    		 async: false,
    		 success: function (data) {
    		 	useShared=data.d.UseShared;
    		 },
    		 error: function (data) {
    		 }
    	 });
    	return useShared;
    }
    </script>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by AmarnathBabu Tuesday, January 31, 2017 10:29 AM
    Tuesday, January 31, 2017 6:15 AM
    Moderator
  • hi, Thanks for the reply. this is working fine for current site.

    but is it possible to identify the same navigation settings of its parent site from subsite? 

    my requirement is that,  

    Home page - Global navigation- need to display Own logo and link to itself 
    subsite - Global navigation inherits from homepage - Inherit logo and link from site above 
    sub-subsite - Global navigation inherits from homepage - Inherit logo and link from site above 
    sub-sub-subite - Global navigation stops inherits from homepage - display Own logo and link to itself 

    so from subsite/sub-subsite, i need to find the navigation setting for parent sites.

    Any suggestion on this?

    thanks,

    Amarnath


    Tuesday, January 31, 2017 10:54 AM
  • Hi Amarnath,

    The following code for your reference:

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){
    	console.log(isParentWebUseShared());
    });
    function isParentWebUseShared(){
    	 var useShared=false;	 
    	 var url = getParentwebURL() + "/_api/web/Navigation/UseShared";
    	 $.ajax({
    		 url: url,
    		 method: "GET",
    		 headers: { "Accept": "application/json; odata=verbose" },
    		 async: false,
    		 success: function (data) {
    		 	useShared=data.d.UseShared;
    		 },
    		 error: function (data) {
    		 }
    	 });
    	return useShared;
    }
    function getParentwebURL(){
    	 var webURL="";	 
    	 var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/parentWeb/ServerRelativeUrl";
    	 $.ajax({
    		 url: url,
    		 method: "GET",
    		 headers: { "Accept": "application/json; odata=verbose" },
    		 async: false,
    		 success: function (data) {
    		 	webURL=data.d.ServerRelativeUrl;
    		 },
    		 error: function (data) {
    		 }
    	 });
    	return webURL;
    }
    </script>

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, February 1, 2017 1:40 AM
    Moderator