Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I prevent SharePoint 2010 from removing/stripping JavaScript and certain CSS elements?

If you use the in-browser HTML editor that comes with SharePoint 2010, when you insert certain CSS selectors (like nth-child) or any JavaScript at all, SharePoint will strip those elements out before saving the page. One could argue that this is for security, but on an intranet site it doesn't matter (what security threat could nth-child pose? Really?).

So I'm getting frustrated at how much SharePoint decides it wants to strip out of whatever HTML you enter in, and I'd like to know how to disable that, so I can enter whatever I like in the HTML editor.

Or am I asking for too much, and is there another, easier way to edit pages without having anything removed?

like image 909
qJake Avatar asked Nov 23 '11 18:11

qJake


1 Answers

This is a 2 part question since the styles need to be addressed in one way and the JavaScript in another.

  1. Styles

"If the HTML editor detects new Cascading Style Sheet (CSS) classes whose names have the prefix ms-rteCustom-XXXX, where XXXX is the display name of the classes unique to the page, it displays the new set of custom styles instead of the default set."

http://msdn.microsoft.com/en-us/library/ms551040.aspx

  1. JavaScript

SharePoint 2010 HTML Editor does not like in-line scripts. Instead you should save the script as a text file and reference it in the HTML editor:

http://sharepointadam.com/2010/08/31/insert-javascript-into-a-content-editor-web-part-cewp/

like image 71
Jon Reid Avatar answered Sep 22 '22 21:09

Jon Reid