Answers for "remove script tags from html nodejs"

0

remove script tags from html nodejs

# Remove script tags from html nodejs

function stripScripts(s) {
    var div = document.createElement('div');
    div.innerHTML = s;
    var scripts = div.getElementsByTagName('script');
    var i = scripts.length;
    while (i--) {
      scripts[i].parentNode.removeChild(scripts[i]);
    }
    return div.innerHTML;
  }

alert(
 stripScripts('<span><script type="text/javascript">alert(\'foo\');<\/script><\/span>')
);
Posted by: Guest on July-09-2021

Code answers related to "remove script tags from html nodejs"

Browse Popular Code Answers by Language