辛辛苦苦写好的代码不想给别人看?手把手教你隐藏代码!
风小原创 JavaScript
细心的童靴已经发现在风小的博客上点击右键会有提醒框出现(对于火狐用户不适用,文章末尾解释),这其实是隐藏代码的第一步:禁止用户从右键源代码中获取网页代码。这段JavaScript代码较简单,如下:
<script language=javascript>
function click() {
if (event.button==2) {
alert('ctrl+c可以复制 转载注明来自glwzu');
}
}document.onmousedown=click
</script>
右键不能提取代码,那么在IE的“页面”—“查看源代码”中也能够发现。所以第二步的任务就是在“查看源文件”中隐藏代码。
鉴于简便说明,我用隐藏3D相册源代码来举例说明。
1)建立hide.html与ps.htm文件
页面采用框架结构的方式,代码如下:
<html>
<head>
<title>hide</title>
</head>
<frameset cols="1,*" frameborder=0 framespacing=0>
<frame src="ps.htm" name="count" noresize scrolling=no>
<frame src="3Dmap.html" name="index" noresize>
</frameset>
</html>
ps.htm文件可设为空文件,它还有其他用途,此处不解释。
2)在3Dmap.html中,即3D相册源代码的<head></head>之间,添加如下代码
<script language="javascript"> if(top==self)top.location="hide.html" // 若是访问3Dmap界面,则跳转至hide.html </script> <script language=javascript>//IE用户必加!避免右键查看源文件 function click() { if (event.button==2) { alert('不准偷看!'); } }document.onmousedown=click </script>
至此,代码已然完全“隐藏”了,打开3Dmap.html显示的是hide.html中的源代码。点击3D相册与hide.html都可以查看效果。
其实这不算隐藏,已经理解的童靴知道这其实是“李代桃僵”!但是还有一个漏洞,这个漏洞笔者没有专研出来,很囧。这个漏洞就是:一个页面另存为,啥代码都下载下来了,这个比较悲剧,如果此问题没解决,以上方法纯属鸡肋。不过今天明日啥耐心做了,以后再独立更新。
最后就是火狐与IE对于JavaScript兼容问题。火狐用户可以跳过第一步的代码,也就是在第二部中第2)部分的后半部JavaScript代码,是因为火狐对此代码“不理会”,然而右键查看源代码时,显示的是hide.html 中的源代码,故而对于禁用右键的功能可以舍弃。然而IE用户在从右键获取的源代码是3Dmap.html中的源代码,故而IE用户必须禁用右键。
做人要厚道,转载注明来自:http://www.glwzu.com/hide-code.html
您可能会喜欢:
Filed under 原创javascript, 网站相关. Tags: JavaScript
可以学习一下
[回复]
风小 回复:
August 10th, 2010 at 19:09
[回复]
…..想给首页写个效果,卡在数据库处理上~ 晕哦!~
[回复]
风小 回复:
August 10th, 2010 at 19:09
wordpress还没钻研透,所以我也拿它没办法
[回复]
这么辛苦看完,原来是鸡肋。
[回复]
风小 回复:
August 10th, 2010 at 19:29
[回复]
飞猪 回复:
August 10th, 2010 at 19:31
以前换衣服时有过几次试着解密别人的衣服。。
[回复]
风小 回复:
August 10th, 2010 at 19:53
[回复]
不准偷看..
[回复]
风小 回复:
August 10th, 2010 at 20:10
[回复]
呃。。不会代码的路过。顺便点**
[回复]
风小 回复:
August 10th, 2010 at 20:11
[回复]
上来就一个不孕不育的**。。。。
[回复]
风小 回复:
August 10th, 2010 at 21:23
[回复]
说实话你给我看我还未必看得懂~
[回复]
风小 回复:
August 10th, 2010 at 23:19
[回复]
代码如诗~~
你懂的。
小周博客恢复了
[回复]
风小 回复:
August 10th, 2010 at 22:36
[回复]
一般隐藏的浅点,就放倒js文件里。深点再混淆一下
[回复]
风小 回复:
August 10th, 2010 at 23:29
嗯,一般都是这么隐藏的。我写的这个则是完全隐藏了,比较少见吧。
[回复]
我是火狐。。我有罪
[回复]
风小 回复:
August 11th, 2010 at 12:47
[回复]
呵呵 认真看着呢啊 学习下 点击广告了啊 这个和我的好像是一样 呼呼
[回复]
风小 回复:
August 11th, 2010 at 12:46
[回复]
哈哈,一般通过firebug都是可以看到的吧
[回复]
风小 回复:
August 11th, 2010 at 22:22
火狐很变态
[回复]
你的**在那撒?我怎么看不到?
难道是我装了金山网盾的原因?
[回复]
风小 回复:
August 12th, 2010 at 11:45
[回复]
不会写代码的人飘过
[回复]
风小 回复:
August 12th, 2010 at 17:28
我会的也不多,手写也是写不出来的
[回复]
firebug飘过~代码拿走~分享快乐~
[回复]
风小 回复:
August 12th, 2010 at 17:28
[回复]
Done well. I am happy with the value of the advice supplied. I expect that you continue with the brilliant job accomplished.
[url=http://www.we-Margate-locksmith.com]locksmith Margate[/url]
[url=http://abdul931wooten.wordpress.com/]fort worth locksmiths[/url]
[url=http://brett4golden.hpage.com/contact_us_for_an_estimate_24_7_and_get_the_best_of_our_experience_4739_66597101.html]locksmith irvine ca[/url]
[url=http://hialeah-locksmiths.com/blog/component/content/article/1-locksmith/37-lock-fix--combination-lock--high-security-equipment--car-locking.html]hialeah fl locksmith[/url]
[回复]
Your content is obviously probably the most suitable . On the whole impression of the page is definitely amazing .
[url=http://www.aaFortWorth-locksmith.com]fort worth locksmith[/url]
[url=http://www.NorwalkLocksmith.info]Locksmiths in Norwalk[/url]
[回复]
That’s way the bestest aneswr so far!
[回复]
So excited I found this article as it made tnhigs much quicker!
[回复]
Touchdown! That’s a really cool way of puittng it!
[回复]