辛辛苦苦写好的代码不想给别人看?手把手教你隐藏代码!

风小原创 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

您可能会喜欢:

37 Comments.

Leave a comment
  1. 可以学习一下 :evil:

    [回复]

    风小 回复:

    :blaugh: 欢迎,也只是一点小知识,呵呵

    [回复]

  2. …..想给首页写个效果,卡在数据库处理上~ 晕哦!~

    [回复]

    风小 回复:

    wordpress还没钻研透,所以我也拿它没办法

    [回复]

  3. 这么辛苦看完,原来是鸡肋。

    [回复]

    风小 回复:

    :blaugh: 看偶以后的更新吧,让他下载下来也打不开。

    [回复]

    飞猪 回复:

    以前换衣服时有过几次试着解密别人的衣服。。 :evil:

    [回复]

    风小 回复:

    :han:

    [回复]

  4. 不准偷看.. :blaugh:

    [回复]

    风小 回复:

    :evil: 想偷看吗

    [回复]

  5. 呃。。不会代码的路过。顺便点**

    [回复]

    风小 回复:

    :ding: 欢迎!

    [回复]

  6. 上来就一个不孕不育的**。。。。 :han:

    [回复]

    风小 回复:

    :evil:

    [回复]

  7. 说实话你给我看我还未必看得懂~ :evil:

    [回复]

    风小 回复:

    :han: 我懂得也不多哦,像这个问题还没有完善。

    [回复]

  8. 代码如诗~~

    你懂的。

    小周博客恢复了

    [回复]

    风小 回复:

    :rp: 终于恢复了啊 偶马上去 嘿嘿,来我们群哦 109600771

    [回复]

  9. 一般隐藏的浅点,就放倒js文件里。深点再混淆一下

    [回复]

    风小 回复:

    嗯,一般都是这么隐藏的。我写的这个则是完全隐藏了,比较少见吧。

    [回复]

  10. 我是火狐。。我有罪

    [回复]

    风小 回复:

    :dizzy: 我搞不懂火狐。。。

    [回复]

  11. 呵呵 认真看着呢啊 学习下 点击广告了啊 这个和我的好像是一样 呼呼

    [回复]

    风小 回复:

    :laugh: 谢谢了

    [回复]

  12. 哈哈,一般通过firebug都是可以看到的吧

    [回复]

    风小 回复:

    火狐很变态 :han:

    [回复]

  13. 你的**在那撒?我怎么看不到?
    难道是我装了金山网盾的原因?

    [回复]

    风小 回复:

    :han: 文章开头末尾都有 右侧欢迎加入QQ群下面也是。。。。

    [回复]

  14. 不会写代码的人飘过

    [回复]

    风小 回复:

    我会的也不多,手写也是写不出来的

    [回复]

  15. firebug飘过~代码拿走~分享快乐~

    [回复]

    风小 回复:

    :sad: 还是被拿走了

    [回复]

  16. 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]

    [回复]

  17. 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]

    [回复]

  18. That’s way the bestest aneswr so far!

    [回复]

  19. So excited I found this article as it made tnhigs much quicker!

    [回复]

  20. Touchdown! That’s a really cool way of puittng it!

    [回复]

Leave a Reply

:laugh: :cool: :ding: :blaugh: :evil: :close: :han: :rp: more »
click to change 请输入验证码

( Ctrl + Enter )