JavaScript小技巧

1.将彻底屏蔽鼠标右键,无右键菜单

<body oncontextmenu="window.event.returnvalue=false">
<SCRIPT LANGUAGE=javascript>

function click() {
    alert('禁止你的左键复制!') }
    function click1() {
        if (event.button==2) {
            alert('禁止右键点击~!') 
        }
    }
    function CtrlKeyDown(){
       if (event.ctrlKey) {
      alert('不当的拷贝将损害您的系统!')
    } } document.onkeydown=CtrlKeyDown; document.onselectstart=click; document.onmousedown=click1;
} </SCRIPT>

  

也可以用于网页中Table框架中

<table border oncontextmenu=return(false)><td>no</table>

2.取消选取、防止复制

<body onselectstart="return false">

3.不准粘贴

<body onpaste="return false">

4.防止复制

<body oncopy="return false;" oncut="return false;">

5.IE地址栏前换成自己的图标

<link rel="Shortcut Icon" href="favicon.ico">

6.关闭输入法

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

7.网页将不能被另存为

说明:<noscirpt>的用法很广,其中一条就是可以使JS广告失效。

<noscript><iframe src=*.html></iframe></noscript>
<noscript>
    <iframe src="*.htm"></iframe>
 </noscript>
<SCRIPT language=javascript>
if (window.Event)
    document.captureEvents(Event.MOUSEUP);
    function nocontextmenu(){
        event.cancelBubble = true
        event.returnValue = false;
        return false;
    }

    function norightclick(e){
        if (window.Event){
            if (e.which == 2 || e.which == 3)
                return false;
            }
            else if (event.button == 2 || event.button == 3){
                event.cancelBubble = true 
                event.returnValue = false;
                return false;
            }
    }
    document.oncontextmenu = nocontextmenu; // for IE5+
    document.onmousedown = norightclick; // for all others
</SCRIPT>                    

  

8.查源文件

<input type=button value="查看网页源代码" onclick="window.location = 'view-source:'+'http://www.cnblogs.com/liumengdie/p/8251331.html';">

9.COOKIE脚本记录

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (documents.cookie.length > 0) {
    offset = documents.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = documents.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
        end = documents.cookie.length;
        returnvalue=unescape(documents.cookie.substring(offset, end))
      }
    }
    return returnvalue;
  }
function loadpopup(){
  if (get_cookie('popped')==''){
    openpopup()
    documents.cookie="popped=yes"
  }
}

  

原文地址:https://www.cnblogs.com/liumengdie/p/8251331.html