Skip to main content
1 of 3
John John
  • 1
  • 49
  • 258
  • 603

how to reference the Site Collection URL inside the src attribute

I added a custom script to my "Style Library" folder under a site collection , the site collection url is as follow http://servername/HR. so to reference the script inside my master page i wrote the following :-

<script  type="text/javascript" src="/hr/Style%20Library/Custom JS/HideTreeViewFolder.js" ></script>

where i am manually referencing the /hr/ in side the src, so can i make this more dynamic and get the site collection url dynamically, so if i move the site collection to another URL the script will still get referenced ?

now i tried adding ".." sand seems it will correctly reference the folder inside the site collection,, but not sure if this is valid ?

  <script  type="text/javascript" src="../Style%20Library/Custom JS/HideTreeViewFolder.js" ></script>
John John
  • 1
  • 49
  • 258
  • 603