Search code examples
javascripthtmlcsssharepointsharepoint-2010

Path to HTML external CSS and Javascript while using Sharepoint 2010 Content Editor


I frequently use Sharepoint 2010 content editors to display Custom HTML. Within my HTML files I also link to external CSS and Javascript files. All of these files are stored in document libraries, organized by folders. Each folder contains a single HTML, CSS and JS file.

When I edit these files, I use offline copies saved on my desktop and then I upload them to SharePoint and overwrite the previous version.

The issue I have is in relation to the src path in the HTML file for the CSS and JS files. When I edit them offline I only use the filename since they are stored in the same folder on my desktop. When I upload them to SharePoint, the path no longer works even though the CSS and JS is in the same folder. The only way I have been able to make it work is to change the path to the full path to each CSS and JS file, ie. "https://SharePointSite.com/Full_Path_to_JS_and_Css".

I would like reference a path to the file on sharepoint without having to use the full path.

Any assistance with be greatly appreciated, Thank you


Solution

  • Take the full path and replace the directories with /../. You might have to do this a bunch of times, sharepoint can be pretty deep.

    So

    https://SharePointSite.com/dir1/dira/Full_Path_to_JS_and_Css".

    would become ../../../Full_Path_to_JS_and_Css".