I am trying to implement the JS code given here:


So that all external links open in a new window. I copied the JS into notepad and saved it in a new folder, StyleLibrary/scripts. However, I keep getting errors on the code when I look at dev tools: enter image description here

I tried the original version with script tags, but it gave me uncaught syntax error on "<"... I also changed the $ to jQuery just to see if it would work.

The script link I added looks like the following:

<!--SPM:<SharePoint:ScriptLink language="javascript" Defer = "true" runat="server" Localizable="true" name="~sitecollection/Style Library/scripts/externalLinkNewWindow.js" />-->

Any Ideas as to why I keep getting these errors? The code isn't running because of them.

  • Start with the easy stuff: 1) Is Jquery Loaded, you didn't post a script tag so I wouldn't know, also make sure it isn't loaded in 2 script tags as all sorts of havoc can ensue then 2) The preferred style for calling Jquery now is "$" or $(document).ready(function(){//code goes here}); – tekiegreg Sep 29 '16 at 20:59
  • Jquery must be loaded, i use it on other pages... I changed it back to $ – Sabien Ambrose Sep 29 '16 at 21:17
  • 1
    sounds like a loading order then, this might be trying to run prior to jQuery being loaded – Eric Alexander Sep 29 '16 at 21:43

Make sure that jQuery linking lines should come first before that your external js files, For example

    <script src="jquery-1.12.4.min.js"></script>
    <script src="Test.js"></script>

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.