zoukankan      html  css  js  c++  java
  • 禁止查看源文件方法总结和js代码下载

    一些禁止查看源文件的脚本,用在网页中,能起到防止别人复制等效果,但是也可以通过其他办法看到源代码,或是复制里面的内容。下面的方法都是一些基本的js脚本,简单的用用就行了,真正能防到什么程序,谁也不好说。有句话说的好,真正做的好的页面,就不怕被人仿、复制、看,本来互联网就是个开放的嘛。

    锁定右键
    将网页中的换为如下代码即可:

    <body oncontextmenu="return false" ondragstart="return false" onselectstart ="return false" onselect="document.selection.empty()" oncopy="document.selection.empty()" onbeforecopy="return false" onmouseup="document.selection.empty()">


    拒绝另存

    在和之间加入如下代码:

    <noscript><iframe src="/*>";</iframe></noscript>


    禁止查看源代码


    尽管通过以上方式屏蔽了右键查看源文件,拒绝了复制和另存,但通过工具栏的【查看】-【源文件】仍会使网页失锁!


    要彻底禁止查看源文件,可通过零框架技术解决——将页面分为左右两帧,左帧的宽度为0,载入空页面文件“null.htm”;右帧载入要保护代码的页面,框架面页为index.htm,代码如下:

    <html> 
    <head> <title>欢迎光临--笑申博客--</title> </head> 
    <frameset cols="0,*" frameborder="NO" border="0" framespacing="0">
       <frame src="/null.htm" name="leftFrame" scrolling="NO" noresize>
       <frame src="/index.html" name="mainFrame">
    </frameset><noframes></noframes>
    </html> 


    同时,已被锁定右键、禁止另存的主面页(原代码见上)命名为 “index.html”,再添如下代码,以防被独立打开:

    <script language="javascript"> if(top==self)top.location="index.html" </script>


    ***//防止被别人框架~~~~~~~~~~~~~~~

    <SCRIPT language=javascript>
    if (top.location != self.location){top.location=self.location; }
    </SCRIPT>

    ~~~~~~~~~~~~~~~~~~~~~~~~~~


    取消选取、防止复制

    <SCRIPT language=JavaScript>
    window.ClearEvent=function(){event.cancelBubble=false;var sSrcTagName=event.srcElement.tagName.toLowerCase();
    return (sSrcTagName=="textarea" || sSrcTagName=="input" || sSrcTagName=="select");}
    window.ClearKey=function(){event.cancelBubble=false;var iKeyCode=event.keyCode;return !(iKeyCode==78 && event.ctrlKey);}
    with (window.document){oncontextmenu=onselectstart=ondragstart=window.ClearEvent;onkeydown=window.ClearKey;}
    </SCRIPT>


    <BODY oncontextmenu=self.event.returnValue=false onselectstart="return false">


    <body onselectstart="return false"> 


    不准粘贴

    onpaste="return false" 


    防止复制

    oncopy="return false;" oncut="return false;"


    关闭输入法

    <input style="ime-mode:disabled">

  • 相关阅读:
    事务(十四)
    事务(十三)
    事务(十二)
    事务(十一)
    事务(十)
    try中定义输入流报错:Try-with-resources are not supported at language level '5'
    IDEA新建时没有java class选项
    Hex编码
    Git Bash安装及常规使用
    PostgreSQL数据库
  • 原文地址:https://www.cnblogs.com/luluping/p/1441679.html
Copyright © 2011-2022 走看看