剪切板与正则表达式测试
<html>
<head>
<title>剪切板与正则表达式测试</title>
<script language="javascript" type="text/javascript">
//复制到剪切板
function copyToClipboard()
{
var d=document.all("source").value;
d=FilterScripts(d);
d=FilterHtml(d);
window.clipboardData.setData('text', d);
}
//过滤脚本语言
function FilterScripts(content)
{
content = content.replace(/<script(.|\n)*\/script>\s*/ig, "");
content = content.replace( /<[^>]+/ig, function($0){return $0.replace(/\s*on\w+\s*=\s*[^ ]+/ig, "")});
content = content.replace(/(javascript|jscript|vbscript|ecmascript|vbs):\w+(\(\)|\(\w+\))/ig,"#");
return content;
}
//过滤HTML代码
function FilterHtml(content)
{
return content.replace(/<\/?(?!br|p|img)[^>]*>/gi,"");
}
//显示内容
function DisplayContent(content)
{
if(content != null)
{
document.all("display").value = content.Trim();
}
}
// 去掉所有空格
String.prototype.TrimAll = function() {
return this.replace(/\s/g,"");
}
// 去掉左右空格
String.prototype.Trim = function() {
return this.replace(/\s+$|^\s+/g,"");
}
</script>
</head>
<body>
<form id="form1">
<div>
<textarea id="source" cols="50" rows="20"></textarea>
<textarea id="display" cols="30" rows="20"></textarea>
<br />
<button onclick="copyToClipboard();">拷贝</button>
<button onclick="DisplayContent(window.clipboardData.getData('text'));">显示</button>
<button onclick="window.clipboardData.clearData('text');document.all('display').value=''">清空</button>
</div>
</form>
</body>
<head>
<title>剪切板与正则表达式测试</title>
<script language="javascript" type="text/javascript">
//复制到剪切板
function copyToClipboard()
{
var d=document.all("source").value;
d=FilterScripts(d);
d=FilterHtml(d);
window.clipboardData.setData('text', d);
}
//过滤脚本语言
function FilterScripts(content)
{
content = content.replace(/<script(.|\n)*\/script>\s*/ig, "");
content = content.replace( /<[^>]+/ig, function($0){return $0.replace(/\s*on\w+\s*=\s*[^ ]+/ig, "")});
content = content.replace(/(javascript|jscript|vbscript|ecmascript|vbs):\w+(\(\)|\(\w+\))/ig,"#");
return content;
}
//过滤HTML代码
function FilterHtml(content)
{
return content.replace(/<\/?(?!br|p|img)[^>]*>/gi,"");
}
//显示内容
function DisplayContent(content)
{
if(content != null)
{
document.all("display").value = content.Trim();
}
}
// 去掉所有空格
String.prototype.TrimAll = function() {
return this.replace(/\s/g,"");
}
// 去掉左右空格
String.prototype.Trim = function() {
return this.replace(/\s+$|^\s+/g,"");
}
</script>
</head>
<body>
<form id="form1">
<div>
<textarea id="source" cols="50" rows="20"></textarea>
<textarea id="display" cols="30" rows="20"></textarea>
<br />
<button onclick="copyToClipboard();">拷贝</button>
<button onclick="DisplayContent(window.clipboardData.getData('text'));">显示</button>
<button onclick="window.clipboardData.clearData('text');document.all('display').value=''">清空</button>
</div>
</form>
</body>