Stripping HTML Tags
From All n One's bxp software Wixi
1 Overview
In bxp we often have issues with certain special characters causing problems when importing and exporting data in modules like Key Stats or when using the TinyMCE rich text editor. Anywhere there is custom code and exporting of data using HTML, JavaScript tags can cause problems.
2 Stripping Tags
In order to fix code or remove harmful tags such as script tags that contain JavaScript the below code can be used to remove any tag and its contained data from an object.
function fn_StripTags(strData_Value, strTag_Name) {
var div = document.createElement('div');
div.innerHTML = strData_Value;
var scripts = div.getElementsByTagName(strTag_Name);
var i = scripts.length;
while (i--) {
scripts[i].parentNode.removeChild(scripts[i]);
}
return div.innerHTML;
}
So say we have a small html table stored in an element and some JavaScript at the end of the element but we need to extract just the table and get rid of the JavaScript we would do the following.
fn_StripTags(document.getElementById('MyElement').value, 'script');Calling this function will remove all script tags and contained code from the object.