Showing posts with label Css disappears. Show all posts
Showing posts with label Css disappears. Show all posts

Friday, 7 December 2012

Javascript or Css disappears in Content Editor Webpart - CEWP

Problem:

Recenlty I faced a problem that I was writing some html along with javascript tag with some code in the CONTENT EDITOR WEBPART (CEWP). As soon as I save the page, all the tags of javascript disppeared or removed from CEWP. I googled, but did not find any solution.

Solution:

What I did, encapsulated the script and html within "CDATA" section, actually sharepoint 2010, it was removing all such script tags from the CEWP becasuse of secrutiy purpose, it removes all the script which could threaten or inject. Thus CDATA solved my problem.

Updated (Feb 18 2013) :
On my friend's request FAZ, am including an example to explain it littile bit more on this topic.

Sometimes you edit a page in sharepoint designer, and add javascript snippet in the page, on saving the page it prompt you a message that "unsafe code will removed...", and when the page is saved you will notice that the javascript snippet you just added is removed.
For Example:
1. Edit a page and add some javascript code snippet in the Content Editor Webpart and save.
 (Content Editor webpart is inserted using "Insert" tab in the SharePoint Designer, and then "Webpart" menu, and then select "Content Editor")
2. When you will save , it will prompt a message just shown in the figure below:

3. When you will click "Yes", you will notice that the javascript snipped you just added have been removed from the page.
So for that we have to keep our javsacirpt / CSS snippet in CDATA wrapping as shown below:


<script type="text/javascript"><![CDATA[
function Test()
{
alert("tested!");
}
]] </script>

Then it will not remove your snipped from the page.

Hope this help!!

Test Email without sending Email to User - C# / C-Sharp - DotNet

Sometimes we may want to test email functionality without sending email to actual user. Email will be saved locally so that we can verify ...