Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to customize a Sharepoint 2013 team site.

I created a copy of seattle.master and set it as default master page via context menu.

I added my custom CSS within head tages like so:

<SharePoint:Scriptlink runat="server" Name="https://sharepoint.osce.org/sites/the_new_osce_portal/custom/jquery-1.10.2.min.js" Language="javascript" />

works!

I added jQuery like so:

<SharePoint:ScriptLink language="javascript" name="/sites/the_new_osce_portal/custom/jquery-1.10.2.min.js" runat="server" Localizable="false" />

When I reload the page I get:

      <html><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"><meta name="Robots" content="NOINDEX " /></head><body></body>
      <script type="text/javascript">
                var gearPage = document.getElementById('GearPage');
                if(null != gearPage)
                {
                gearPage.parentNode.removeChild(gearPage);
                document.title = "Error";
                }
            </script>
      </html>

The link to jQuery is correct.

I now have a solution by which I simply add the normal script tag like so:

<script type="text/javascript" src="/sites/the_new_osce_portal/custom/jquery-1.10.2.min.js"></script>

Works like a charm.

Now my questions:

  1. Is there any objection against my "fix"

  2. Why doesn't it work in the first place?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

The log file should get you the path that SharePoint unsuccessfully tries to resolve. Try adding "~sitecollection" first in the ScriptLink like:

<SharePoint:ScriptLink language="javascript" name="~sitecollection/custom/jquery-1.10.2.min.js" runat="server" Localizable="false" />

but this will only work inside the "the_new_osce_portal" Site collection.

share|improve this answer
    
Thanks worked like a charm. –  Juergen Riemer Jan 8 at 8:51
add comment

In the 2nd statement you should have used the site collection specific TOKEN as in:

<SharePoint:Scriptlink runat="server" Name="~sitecollection/Style Library/[YOUR SITE]/PathToJqueryLib/jquery-1.10.2.min.js />

The issue with your 3rd (also known as Client-Side JavaScript library reference) is that such constructs do no recognize token-based constructs so that site collection relative path cannot be constructed dynamically. I would say is pure luck that the page at which you are most likely looking it just happens that it matches the URL to the library. As soon as you shall have a more deeper structure this won't work most likely.

Master page is a server side artifact, do try to use recommanded approach (use ScriptLink) to avoid future issues. Read more here http://tommdaly.wordpress.com/2010/12/16/scriptlink-vs-whats-the-difference/

There is also the possibility to use a Custom action to load the library on any page using the ScriptSrc attribute as in http://blog.lekman.com/2013/01/scriptlink-registration-in-sharepoint.html

share|improve this answer
    
+1 for the explanations and useful links.. thanks –  Juergen Riemer Jan 8 at 8:52
    
happy to help, thank you! –  C. Marius - MVP Jan 8 at 9:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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