Search This Blog

Wednesday, June 19, 2019

How to remove special characters and codes (using jQuery) from SharePoint rendered html?

Welcome to designers dairy, Here we are going to discuss,How to remove special characters and codes (using jQuery) from SharePoint rendered html
Step1:
It is a big headache, when you render the html  in share-point, There are lot of special characters especially  char code "#8203".
Step2:
To remove this special code include in html while rendering the page, we have to write a jquery script 

Script:
    $(document).ready(function()
{
jQuery('.OnboardingOnlinePortal-wrapper').each(function(index,element)  { 

       var exp = new RegExp(String.fromCharCode(8203),"g");
       var editor= jQuery(element);
       var txt = editor.html()
           txt = txt.replace(exp,'');
           txt = txt.replace(/ /g,' ')
           txt = txt.replace(/ {2,}/g,' ');
       editor.html(txt);
  });
  return true;
 });

Step3:
In my scenario, I have included this script in the Page layout, based on your requirements, you can add in Pages or master pages.
To add the script in Page layout below is the placeholder 
  <script>//<![CDATA[
    $(document).ready(function()
{
jQuery('.OnboardingOnlinePortal-wrapper').each(function(index,element)  {

       var exp = new RegExp(String.fromCharCode(8203),"g");
       var editor= jQuery(element);
       var txt = editor.html()
           txt = txt.replace(exp,'');
           txt = txt.replace(/&nbsp;/g,' ')
           txt = txt.replace(/ {2,}/g,' ');
       editor.html(txt);
  });
  return true;
 });

//]]>
 </script>
Step3:

Thanks for reading the article.Stay Tuned on www.webdesignersdairy.com  for more updates on SharePoint.

No comments:

Post a Comment

Validating to select in sequencial order using angular

    < input type = "checkbox" (change) = "handleSelectTaskItem($event, taskItem)" [checked] = " taskItem . i...