1

I have included some javascript to a master page of a site collection. The script makes a clickable button directs to two sites which when an internal user click on it user directs to a internal accessible site while an external user click it directs to a external accessible site.

This button appears in all the sites except when I go to the site settings page of a particular site page.

Does that means the script is not working in site settings page? It works in site settings when I activate SharePoint Server Publishing feature in site features.

I'll add the code below you to clarify the issue

<script type="text/javascript">
var clientContext;
var user;

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);

function sharePointReady() {


    clientContext = SP.ClientContext.get_current();

    user = clientContext.get_web().get_currentUser();

    clientContext.load(user);
    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);
}
function onQuerySucceeded() {

var cuser = user.get_email();
userem = cuser.replace(/.*@/, "");


if (userem == "xxx.com") {

document.getElementById("homehelp").innerHTML = "<a id='bookmarkmy' href='site url for internal users' title='Click here for help with this portal' target='_blank'><img src='image url' width='20px' height='20px' style='margin-bottom:-5px;'>&nbsp;&nbsp;HELP</a>";

} else { 
  document.getElementById("homehelp").innerHTML = "<a id='bookmarkmy' href='site url for external users' title='Click here for help with this portal' target='_blank'><img src='image url' width='20px' height='20px' style='margin-bottom:-5px;'>&nbsp;&nbsp;HELP</a>";
}


}
function onQueryFailed(sender, args) {
    alert('Error: ' + args.get_message());
}
</script>
0

Yes. You are needed to activate this feature to achieve your goal. It is clearly mentioned in that feature. Have a look on the description of this feature.

SharePoint Server Publishing Infrastructure:

Provides centralized libraries, content types, master pages and page layouts and enables page scheduling and other publishing functionality for a site collection.

enter image description here Moreover check this answer

if (userem == "xxx.com") {

document.getElementById("homehelp").innerHTML = "<a id='bookmarkmy' href='site url for internal users' title='Click here for help with this portal' target='_blank'><img src='image url' width='20px' height='20px' style='margin-bottom:-5px;'>&nbsp;&nbsp;HELP</a>";

} else { 
  document.getElementById("homehelp").innerHTML = "<a id='bookmarkmy' href='site url for external users' title='Click here for help with this portal' target='_blank'><img src='image url' width='20px' height='20px' style='margin-bottom:-5px;'>&nbsp;&nbsp;HELP</a>";
}

homehelp may not exist in Site Settings page. Check it.

  • But the issue is i have added a favorite button with java script which bookmark the particular page, that button shows in all the pages without any issue even in the site settings page how is this happening ?? :O – GTNSP Oct 6 '15 at 5:15
  • Are you using same master page for System Master Page also? sharepoint.stackexchange.com/a/158675/21421 – Atish Dipongkor - MVP Oct 6 '15 at 5:18
  • Yes same master page – GTNSP Oct 6 '15 at 5:21
  • Can you check this script in the site settings page? Open the source of site settings page from browser and try to find your script block – Atish Dipongkor - MVP Oct 6 '15 at 5:26
  • Yes the script is there but how it doesn't show in the page when loading ?? – GTNSP Oct 6 '15 at 5:50
0

It looks like the Site Settings page doesn't load sp.js.

Try adding this before your script:

<script type="text/javascript" src="_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="_layouts/15/sp.js"></script>

See this thread for more.

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.