2011-04-17 12 views
5

jQueryを使用してasp.netページにテキストをコピーするのを防ぐ方法を教えてください。jQueryを使用してテキストをコピーできないようにするには?

+6

男、これは「右クリックしない」と同じくらい悪いです。すべての人に問題を保存してください。あなたがしているのはあなたのユーザーを罰することだけです。 –

+0

ページがasp.netやその他のサーバー側の言語で解析されても、常にhtml(通常のWebページの場合)です。 –

+0

ハッハッハッハ 私はそれも本当に嫌いですが、私の顧客はそれを望んでいます! – HAJJAJ

答えて

9

あなたは右クリックを無効にしても、コピーコマンドキーの組み合わせ「のCtl + C」を検出するために、ドキュメント上からkeyupイベントをバインドし、falseを返すことができます。 Ctl + Cを検出するために

jQuery(document).bind("contextmenu", function(e) { 
e.preventDefault(); 
}); 

:右クリックを無効にするには

jQuery(document).ready(function() 
{ 
    var ctlPressed = false; //Flag to check if pressed the CTL key 
    var ctl = 17; //Key code for Ctl Key 
    var c = 67; //Key code for "c" key 

    jQuery(document).keydown(function(e) 
    { 
     if (e.keyCode == ctl) 
      ctlPressed = true; 
    }).keyup(function(e) 
    { 
     if (e.keyCode == ctl) 
      ctlPressed = false; 
    }); 

    jQuery(".your-no-copy-area").keydown(function(e) 
    { 
     if (ctlPressed && e.keyCode == c) 
      return false; 
    }); 
}); 
1

透かしはあなたのソリューションです。私は簡単にJavascriptを無効にすることができます。

+1

それがテキストなら、うーん...うんざりだ。 –

+0

透かしは良いですが、アラビア文字では機能しません! – HAJJAJ

+0

ええと、あなたのテキストをイメージに変えれば、目の不自由なユーザーはあなたのウェブサイトをもう訪問しなくなります(スクリーンリーダーは、スクリーンリーダーがイメージを解釈する方法がないため、 )。 –

1

これは通常、眉をひそめるされていますが、中に行う必要がある場合は、here is a plugin

+0

mmm、これは格子状に見える 私は今それを試してみます。ありがとうございます。 ありがとうございます。 – HAJJAJ

1

はよく私はこれがようにするためにコードの多くを使用:

1-する権利を無効にしますクリック:

<script src="js/jquery.min.js" type="text/javascript"></script>  
<script type="text/javascript" language="javascript"> 
    $(function() { 
     $(this).bind("contextmenu", function (e) { 
      e.preventDefault(); 
      alert("Copy is not allowed"); 
     }); 
    });  
</script> 

選択2-無効

<script type="text/javascript"> 

    /*********************************************** 
    * Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com) 
    * This notice MUST stay intact for legal use 
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code 
    ***********************************************/ 

    function disableSelection(target) { 
     if (typeof target.onselectstart != "undefined") //IE route 
      target.onselectstart = function() { return false } 
     else if (typeof target.style.MozUserSelect != "undefined") //Firefox route 
      target.style.MozUserSelect = "none" 
     else //All other route (ie: Opera) 
      target.onmousedown = function() { return false } 
     target.style.cursor = "default" 
    } 

    //Sample usages 
    //disableSelection(document.body) //Disable text selection on entire body 
    //disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv" 

VAR alltables = document.getElementsByTagName( "テーブル")(VARに対する I = 0。 i < alltables.length;私は) disableSelection(ページ上のすべてのテーブル内のalltables [i])と//無効にテキスト選択

3-Iは今、すべて完了bodyタグの終わり

<script type="text/javascript"> 
    var somediv = document.getElementById("page-wrap") 
    disableSelection(somediv) //disable text selection within DIV with id="page-wrap" 
    </script> 
<script type="text/javascript"> 
    disableSelection(document.body) //disable text selection on entire body of page 
</script> 

にそれらを追加する++します.. ...

本当にとても役に立ちました。

関連する問題