Change one SharePoint site link in the Global Navigation redirect to another site for all users except one

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/280815

Pregunta

For example, a site in the global navigation, when clicked should redirect to another site for all users except one. Also, users who have saved the site as bookmarks should be redirected too when they open the link. How does the .js file look like and where should I add it? Any help appreciated.

¿Fue útil?

Solución

You could update the link url when DOM loaded.

For example:

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript">
        function GetCurrentUser() {            
            var userid = _spPageContextInfo.userId;
            var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
            var requestHeaders = { "accept": "application/json;odata=verbose" };

            return $.ajax({
                url: requestUri,
                contentType: "application/json;odata=verbose",
                headers: requestHeaders
            });
        }
        $(function () {
            GetCurrentUser().done(function (data) {
                alert(data.d.Title);
                if (data.d.Title == "usera") {                    
                    $('a[href="/cmu"]').attr('href', "https://www.google.com/");
                }
            })            
        })        
    </script>

implement JavaScript in master page of SharePoint 2013

Licenciado bajo: CC-BY-SA con atribución
scroll top