0

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.

0

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

| improve this answer | |
  • Thanks @Lee_MSFT. The code definitely helped out. Although I replaced the line '$('a[href="/cmu"]').attr('href', "google.com/");' with location.href = "url". Appreciate it! – Anubhav Jain May 27 at 16:06

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.