0

I tried to reference the js files in my SharePoint pages but no way. I tried the follwing links:

<script type="text/javascript" language="javascript" src="/_layouts/customscriptfolder/scriptfile.js"/>
<script type="text/javascript" language="javascript" src="/SiteAssets/scriptfile.js" />
<script type="text/javascript" language="javascript" src="/Style Library/js/scriptfile.js" />

//and

<SharePoint:ScriptLink id="ScriptExternalJs" runat="server"  Name="/Style Library/js/TestScript.js" Localizable="false" ></SharePoint:ScriptLink>
<SharePoint:ScriptLink runat="server" Name="/scripts/TestScript.js"></SharePoint:ScriptLink>

1 Answer 1

0

Use ScriptLink with URL tokens to properly reference JavaScript files.

Examples

To specify the URL of the parent site collection of the current website, use ~sitecollection token:

 <SharePoint:ScriptLink language="javascript" name="~sitecollection/SiteAssets/Script.js" runat="server"  />

To specify the URL of the current website, use ~site token:

<SharePoint:ScriptLink language="javascript" name="~site/SiteAssets/Script.js" runat="server"  />

To specify the URL of the Layouts virtual folder for the current website, use ~layouts token:

<SharePoint:ScriptLink language="javascript" name="~layouts/Contoso/Script.js" runat="server"  />

References

URLs and tokens in SharePoint 2013

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.