SharePoint – Use Javascript


Hello everyone. Today I want to show you how to use Javascript on your SharePoint websites.

To show you how this works I created a Javascript file which applies a CSS file to a SharePoint Page. Here are my scripts:

Javascript:

var path = "/Style Library/Custom";
var style = document.createElement('link');
style.rel = 'stylesheet';
style.type = 'text/css';
style.href = path + '/HideRecentlyModified.css';
document.getElementsByTagName('head')[0].appendChild(style);

CSS:

.s4-recentchanges
{
display: none;
}

After I created those scripts I uploaded them to my SharePoint website.

sharepoint_styles_library_scripts

Now add a Content Editor Webpart to the SharePoint Page you want to apply your Javascript file to.

 

Now start editing your Content Editor Webpart and click on Edit HTML Source to modify its HTML Code.

sharepoint_content_editor_webpart_edit_html_source

Now add the following code to the HTML Source window:

<script src="/Style Library/Custom/SwitchCSS.js"></script>

sharepoint_html_source_javascript_path

Now click on OK and save your changes. That´s it. This is all you need to do when you want to apply a Javascript file to your SharePoint pages. I hope my post was useful for you.

Sources:

http://www.codeproject.com/Articles/591062/How-to-add-JavaScript-and-CSS-f

http://www.codeproject.com/Tips/493775/Apply-CSS-styles-to-SharePoint-Web-parts

http://techtrainingnotes.blogspot.co.at/2012/05/adding-javascript-and-css-to-sharepoint.html

Advertisements
Tagged , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: