Referencing javascript library in content editor webpart












2















So i have added content editor webpart in NewForm.aspx and reading the code to javascript file called HideFields.ps1. SO the script as below:



HideFields.ps1



 <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" language="javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {

$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function(xData, Status) {
var xml = xData.responseXML.xml;

//If the current User does belong to the group "Test Group"
if (xml.search('Test Group') == -1)
{
$('td.ms-formlabel:contains("Description")').parent().hide();

}
}

});

});
</script>


The above script work as expected if i reference jquery library and SPService library externally.



What it does not work if i have save the file in the same location of this javascript file (HideFields.ps1).





<script type="text/javascript" language="javascript" src="~siteCollection/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


I tried also this one since the all the files existed in the same location





<script type="text/javascript" language="javascript" src="jquery.SPServices-0.7.1a.min.js"></script>









share|improve this question



























    2















    So i have added content editor webpart in NewForm.aspx and reading the code to javascript file called HideFields.ps1. SO the script as below:



    HideFields.ps1



     <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" language="javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
    <script type="text/javascript">

    $(document).ready(function() {

    $().SPServices({
    operation: "GetGroupCollectionFromUser",
    userLoginName: $().SPServices.SPGetCurrentUser(),
    async: false,
    completefunc: function(xData, Status) {
    var xml = xData.responseXML.xml;

    //If the current User does belong to the group "Test Group"
    if (xml.search('Test Group') == -1)
    {
    $('td.ms-formlabel:contains("Description")').parent().hide();

    }
    }

    });

    });
    </script>


    The above script work as expected if i reference jquery library and SPService library externally.



    What it does not work if i have save the file in the same location of this javascript file (HideFields.ps1).





    <script type="text/javascript" language="javascript" src="~siteCollection/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


    I tried also this one since the all the files existed in the same location





    <script type="text/javascript" language="javascript" src="jquery.SPServices-0.7.1a.min.js"></script>









    share|improve this question

























      2












      2








      2








      So i have added content editor webpart in NewForm.aspx and reading the code to javascript file called HideFields.ps1. SO the script as below:



      HideFields.ps1



       <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
      <script type="text/javascript" language="javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
      <script type="text/javascript">

      $(document).ready(function() {

      $().SPServices({
      operation: "GetGroupCollectionFromUser",
      userLoginName: $().SPServices.SPGetCurrentUser(),
      async: false,
      completefunc: function(xData, Status) {
      var xml = xData.responseXML.xml;

      //If the current User does belong to the group "Test Group"
      if (xml.search('Test Group') == -1)
      {
      $('td.ms-formlabel:contains("Description")').parent().hide();

      }
      }

      });

      });
      </script>


      The above script work as expected if i reference jquery library and SPService library externally.



      What it does not work if i have save the file in the same location of this javascript file (HideFields.ps1).





      <script type="text/javascript" language="javascript" src="~siteCollection/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


      I tried also this one since the all the files existed in the same location





      <script type="text/javascript" language="javascript" src="jquery.SPServices-0.7.1a.min.js"></script>









      share|improve this question














      So i have added content editor webpart in NewForm.aspx and reading the code to javascript file called HideFields.ps1. SO the script as below:



      HideFields.ps1



       <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
      <script type="text/javascript" language="javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
      <script type="text/javascript">

      $(document).ready(function() {

      $().SPServices({
      operation: "GetGroupCollectionFromUser",
      userLoginName: $().SPServices.SPGetCurrentUser(),
      async: false,
      completefunc: function(xData, Status) {
      var xml = xData.responseXML.xml;

      //If the current User does belong to the group "Test Group"
      if (xml.search('Test Group') == -1)
      {
      $('td.ms-formlabel:contains("Description")').parent().hide();

      }
      }

      });

      });
      </script>


      The above script work as expected if i reference jquery library and SPService library externally.



      What it does not work if i have save the file in the same location of this javascript file (HideFields.ps1).





      <script type="text/javascript" language="javascript" src="~siteCollection/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


      I tried also this one since the all the files existed in the same location





      <script type="text/javascript" language="javascript" src="jquery.SPServices-0.7.1a.min.js"></script>






      2013 sharepoint-server javascript content-editor-web-part






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 19 at 6:25









      SupermodeSupermode

      1,4211025




      1,4211025






















          2 Answers
          2






          active

          oldest

          votes


















          3














          If site url like http://sp, reference the library as:



          <script type="text/javascript" language="javascript" src="/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


          If site url like http://sp/sites/team, reference the library as:



          <script type="text/javascript" language="javascript" src="/sites/team/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


          Update:



          My test result:



          enter image description hereenter image description here






          share|improve this answer


























          • I have tried this still however it is unable to load library

            – Supermode
            2 days ago











          • Check my test result.

            – Lee_MSFT
            2 days ago



















          0














          Try these 2 options -




          • Place your files in some other custom libraries other than "Site Assets" or "Style Library", and then refer it in your HTML from there.

          • Put your site in trusted locations in Internet Options settings of IE (Settings > Internet Options > Security > Trusted Sites > Sites > Add your site






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "232"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsharepoint.stackexchange.com%2fquestions%2f259616%2freferencing-javascript-library-in-content-editor-webpart%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            If site url like http://sp, reference the library as:



            <script type="text/javascript" language="javascript" src="/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


            If site url like http://sp/sites/team, reference the library as:



            <script type="text/javascript" language="javascript" src="/sites/team/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


            Update:



            My test result:



            enter image description hereenter image description here






            share|improve this answer


























            • I have tried this still however it is unable to load library

              – Supermode
              2 days ago











            • Check my test result.

              – Lee_MSFT
              2 days ago
















            3














            If site url like http://sp, reference the library as:



            <script type="text/javascript" language="javascript" src="/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


            If site url like http://sp/sites/team, reference the library as:



            <script type="text/javascript" language="javascript" src="/sites/team/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


            Update:



            My test result:



            enter image description hereenter image description here






            share|improve this answer


























            • I have tried this still however it is unable to load library

              – Supermode
              2 days ago











            • Check my test result.

              – Lee_MSFT
              2 days ago














            3












            3








            3







            If site url like http://sp, reference the library as:



            <script type="text/javascript" language="javascript" src="/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


            If site url like http://sp/sites/team, reference the library as:



            <script type="text/javascript" language="javascript" src="/sites/team/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


            Update:



            My test result:



            enter image description hereenter image description here






            share|improve this answer















            If site url like http://sp, reference the library as:



            <script type="text/javascript" language="javascript" src="/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


            If site url like http://sp/sites/team, reference the library as:



            <script type="text/javascript" language="javascript" src="/sites/team/Style Library/Scripts/jquery.SPServices-0.7.1a.min.js"></script>


            Update:



            My test result:



            enter image description hereenter image description here







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 days ago

























            answered Mar 19 at 7:44









            Lee_MSFTLee_MSFT

            2,463125




            2,463125













            • I have tried this still however it is unable to load library

              – Supermode
              2 days ago











            • Check my test result.

              – Lee_MSFT
              2 days ago



















            • I have tried this still however it is unable to load library

              – Supermode
              2 days ago











            • Check my test result.

              – Lee_MSFT
              2 days ago

















            I have tried this still however it is unable to load library

            – Supermode
            2 days ago





            I have tried this still however it is unable to load library

            – Supermode
            2 days ago













            Check my test result.

            – Lee_MSFT
            2 days ago





            Check my test result.

            – Lee_MSFT
            2 days ago













            0














            Try these 2 options -




            • Place your files in some other custom libraries other than "Site Assets" or "Style Library", and then refer it in your HTML from there.

            • Put your site in trusted locations in Internet Options settings of IE (Settings > Internet Options > Security > Trusted Sites > Sites > Add your site






            share|improve this answer




























              0














              Try these 2 options -




              • Place your files in some other custom libraries other than "Site Assets" or "Style Library", and then refer it in your HTML from there.

              • Put your site in trusted locations in Internet Options settings of IE (Settings > Internet Options > Security > Trusted Sites > Sites > Add your site






              share|improve this answer


























                0












                0








                0







                Try these 2 options -




                • Place your files in some other custom libraries other than "Site Assets" or "Style Library", and then refer it in your HTML from there.

                • Put your site in trusted locations in Internet Options settings of IE (Settings > Internet Options > Security > Trusted Sites > Sites > Add your site






                share|improve this answer













                Try these 2 options -




                • Place your files in some other custom libraries other than "Site Assets" or "Style Library", and then refer it in your HTML from there.

                • Put your site in trusted locations in Internet Options settings of IE (Settings > Internet Options > Security > Trusted Sites > Sites > Add your site







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 19 at 8:23









                Satyajit PaulSatyajit Paul

                46329




                46329






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to SharePoint Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsharepoint.stackexchange.com%2fquestions%2f259616%2freferencing-javascript-library-in-content-editor-webpart%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown