站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Javascript 专题防止代码复制

防止代码复制

摘要: 防止代码复制
<tr> <td>

//插入 document.body.oncopy event事件中
//或者 <body>的"oncopy"属性
function copyCode()
{
try
{
var range = document.selection.createRange();
if (document.selection.type != "none")
{
var parent = range.parentElement();
var parentName = parent.tagName;
if (parentName != null)
{
if (parentName.toLowerCase() == "pre")
{
// Replace superfluous
tags in a

 block.
var re = /
/gi;
var code = range.htmlText.replace(re, "\r\n");

// Replace non-breaking spaces.
re = /&nbsp;/gi;
code = code.replace(re, " ");

// Replace & characters.
re = /&amp;/gi;
code = code.replace(re, "&");

// Replace < characters.
re = /&lt;/gi;
code = code.replace(re, "<");

// Replace > characters.
re = /&gt;/gi;
code = code.replace(re, ">");

// CJM: Remove colorization
re = /<\/?span([^>])*>/gi;
code = code.replace(re, "");

if (code != null)
{
window.event.returnValue = false;
window.clipboardData.setData("Text", code);
}
}
}
}
}
catch(e) {}
}


<head>
防复制
<script language=javascript src="/blog/js/oncopy.js">
</script>





</head>
<body oncopy="return copyCode();" >
防代码复制,不信你试试(只防止代码复制,其他可以复制)

<table>
<tr>
<td>aa</td>
<td>bb</td>
<td>cc</td>
</tr>
<tr>
<td>dd</td>
<td>ee</td>
<td>ff</td>
</tr>
</table>

&lt;%
option explicit
dim fso
set fso = createobject(&quot;scripting.filesystemobject&quot;)
dim asplines, jslines, aspbytes, jsbytes, aspwords
iterate(server.mappath(&quot;/web_api&quot;))
response.write &quot;ASP:
Total Lines Coded: &quot;
&amp; asplines &amp; &quot;
Total Bytes: &quot;
&amp; aspbytes &amp; &quot;
Total Individual Elements (words) Typed: &quot;
&amp; aspwords
response.write &quot;
JScript:
Total Lines Coded: &quot;
&amp; jslines &amp; &quot;
&quot;
&amp; &quot;Total Bytes: &quot; &amp; jsbytes
function iterate(path)
dim folder, folders, files, file, ts, txt, arr, f
set folder = fso.getfolder(path)
set files = folder.files
dim rx, c
set rx = new regexp
rx.ignorecase = true
rx.global = true
rx.pattern = &quot; +&quot;
for each file in files
if right(file.name,4)=&quot;.asp&quot; or right(file.name,3)=&quot;.js&quot; then
set ts = file.openastextstream
if ts.atendofstream then txt = &quot;&quot; else txt = ts.readall
ts.close
txt = rx.replace(txt,&quot; &quot;)
txt = replace(txt,vbcrlf&amp;vbcrlf,vbcrlf)
arr = split(replace(txt,vbcrlf,&quot; &quot;),&quot; &quot;)
aspwords = aspwords + ubound(arr)
arr = split(txt,vbcrlf)
if right(file.name,4)=&quot;.asp&quot; then
asplines = asplines + ubound(arr)
aspbytes = aspbytes + len(txt)
else
jslines = jslines + ubound(arr)
jsbytes = jsbytes + len(txt)
end if
end if
next
set folders = folder.subfolders
for each f in folders
iterate f.path
next
end function
%&gt;

</body>

</td> </tr> </table>
↑返回目录
前一篇: 正则表达式的应用
后一篇: 正则表达式学习