Files
js-xss/example/strip_tag.js

21 lines
558 B
JavaScript
Raw Permalink Normal View History

2017-03-15 12:45:03 +08:00
/**
* 应用实例去除HTML标签只保留文本内容
*
* @author 老雷<leizongmin@gmail.com>
*/
var xss = require('../');
var source = '<strong>hello</strong><script>alert(/xss/);</script>end';
var html = xss(source, {
whiteList: [], // 白名单为空,表示过滤所有标签
stripIgnoreTag: true, // 过滤所有非白名单标签的HTML
stripIgnoreTagBody: ['script'] // script标签较特殊需要过滤标签中间的内容
});
console.log('text: %s', html);
/*
运行结果
text: helloend
*/