0

Background - I added a webpart to hold my jquery script on a single Sharepoint page. It works fine. In the HTML of the source editor, the script begins:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script>
<script type="text/javascript">....

Now I want to put that same jquery in the master page to use it site wide.

I copied what I had in the webpart and saved it as js to /scripts/outboundlinks.js

In my master page, I put the following just before the closing head tag:

<script src="/Scripts/OutboundLinks.js" type='text/javascript'></script>

and saved / approved my master page.

I'm surfing about on my site and the javascipt is not working. Looking at the loaded scripts in IE developer tool I am getting an error that point to the 1st line referencing the external js library.

What does the master page not like about my script that a webpart with this script will allow? Is it the external reference to jquery? Do I have to have jquery library local to my sharepoint site?

I could just try this - but I am interested in hearing an explanation for this. enter image description here

  • sorry for the mulitple edits. I was getting an error submitting my question until I broke it into pieces. – Sue White May 5 '14 at 17:31
1

I don't think your script file can contain <script> tags. Try loading the jQuery in your master page directly, then having only script (no <script> tags) in the OutboundLinks.js file (loaded after jQuery, of course). So your master page will have:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script>
<script src="/Scripts/OutboundLinks.js" type='text/javascript'></script>

OutboundLinks.js will contain:

if (typeof jQuery != 'undefined') {
    jQuery(document).ready(function($) {
        //rest of code...
  • I'm giving this a try later this evening in production, thank you for the reply. – Sue White May 5 '14 at 20:07
  • That did the trick to take the scripts out of the .js file. Thank you. – Sue White May 6 '14 at 0:22
0

Your link is incorrectly configured. if you start with a / you need everything after .com to be included which should contain at least your site name. Relative paths do not start with / and can be used appropriately. See http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/

  • I think I have to reference the hosted jquery library as such, according to this.. encosia.com/… – Sue White May 5 '14 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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