Whenever I place my js link:

<script src="/sites/xxx/SiteAssets/js/xxx.js" type="text/javascript"></script>


<asp:Content ContentPlaceHolderId="PlaceHolderPageImage" runat="server">

It does not work but it works if I place the entire js such as (rather than a link to the js file containing the same code):

<script type="text/javascript">
    function myPrintBtn() {

I need to add a custom print header and footer and rather than adding the script on each list's DispForm.asxp, I was hoping I could just reference the js file.

1 Answer 1


For classic view, you could inject custom JS by [Add-PnPJavaScriptLink][1], demo:

Connect-PNPOnline -Url https://tenant.sharepoint.com/sites/dev
Add-PnPJavaScriptLink -Name "hideOptionsForRequestAccess" -Url /sites/dev/SiteAssets/hideOptionsForRequestAccess.js -Sequence 9999 -Scope Site

In JS logic, you could add custom logic(check whether url is display form).

Below function is used for different scenario, just for your reference.

(function() {
    // Load the script
    var script = document.createElement("SCRIPT");
    script.src = 'https://code.jquery.com/jquery-1.12.4.js';
    script.type = 'text/javascript';
    script.onload = function() {
        var $ = window.jQuery;          
        var style = $('<style>.ms-accRqCllOt-PrmCmbBx option[value="SharePoint Group#7"]{ display: none; }.ms-accRqCllOt-PrmCmbBx option[value="SharePoint Group#8"]{ display: none; }</style>');
        $('html > head').append(style);     

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.