I have a webpage that uses javascript that I'm trying to implement in my SharePoint 2010 site, but I'm running into some trouble with the javascript. I've tested everything outside of sharepoint and it works fine, so the issue is something I'm doing wrong in sharepoint. I'm trying to implement as follows:

  • html is saved in a .txt file in SiteAssets
  • javascript is saved in a .js file in SiteAssets
  • .txt file includes the following code: <SharePoint:ScriptLink ID="ScriptLink1" language="javascript" name="/SiteAssets/HOME.js" Localizable="false" runat="server"/>

The html loads fine, the javascript doesn't work at all. I suspect the issue is with how I'm trying to link to the javacript file but I'm not sure what I should be doing differently.

Can anyone help?

  • 1
    Instead of using SharePoint:ScriptLink please try to use <script></script> tag to load javascript and see if it works.. – Rohit Waghela Apr 21 '17 at 10:08
  • Tried this - still not working – Roo Apr 21 '17 at 12:18
  • The script tag must work; are you sure your src name is correct? – Danny '365CSI' Engelman Apr 21 '17 at 12:24
  • Trial and error has revealed that it is actually something in my js that sharepoint doesn't like, as I've tried replacing it with a different script and that works. Bizarre, as I've tested it outside of SP and it works fine! – Roo Apr 21 '17 at 13:02
  • I was trying to implement a modified version of this: w3schools.com/howto/howto_js_vertical_tabs.asp - any ideas why it doesn't work on SP? – Roo Apr 21 '17 at 13:16

You have ASP (Server Side) code in your .txt file
But that .txt executes Client Side, so <scriptlink> is a meaningless tag

You can do without one file; Attach your JS code as a UserCustomAction (ScriptLink)

With: https://chrome.google.com/webstore/detail/sp-editor/ecblfcmjnbbgaojblcpmjoamegpbodhd

That code will execute on every page, so you have to check document.location.href if you only want to execute it on a specific page

| improve this answer | |
  • IS there no easier way of doing this when I just want the code on a specific page? – Roo Apr 21 '17 at 12:22

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.