2

返信ありがとうございます。javascript を使用して IE のソース表示ショートカット キーを無効にしたいと考えています。「Ctrl + C」を無効にするために、次の関数を使用しています。

function disableCopy() {
     // current pressed key
     var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
     if (event.ctrlKey && (pressedKey == "c")) {
         // disable key press porcessing
         event.returnValue = false;
     }
}

「Alt + V + C」の組み合わせを無効にする方法を提案できる人はいますか?

4

3 に答える 3

2

すべてのブラウザーには、ソース コードまたは Web ページを表示する機能が組み込まれています。私たちができることは1つです。それはあなたのページで右クリックを無効にしています。

右クリックを無効にするには、次のコードを使用します。

<SCRIPT TYPE="text/javascript">
function disableselect(e){
return false
}
function reEnable(){
return true
}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</SCRIPT>

一つ覚えておいてください。このソースは、firebug またはその他のサードパーティ ツールを使用して表示できます。したがって、これを 100% 行うことはできません。

于 2012-07-11T13:27:56.767 に答える
1

コードの表示を実際に妨げるべきではありません。なんで?

理由

  1. 最終的には、すべての努力の後、誰かが決定した場合でも、コードを見ることができます。

  2. これを行うことで、あなたのウェブサイトを中傷することになります。

  3. 通常、仲間の開発者がコードを見て、javascript を無効にするだけでセキュリティ対策を突破するため、あなたは一種の「初心者」のように振る舞うでしょう。

  4. あなたのコードには、脅威を与えるために使用できる機密情報はありません(私は推測します)。ただし、Web サイトに対して使用できるコードがある場合は、そのコードを削除して Web サイトを安全にすることを検討する必要があります。

組み合わせを無効にする

  document.onkeydown = function(e) {
        if (e.altKey && (e.keyCode === 67||e.keyCode === 86)) {//Alt+c, Alt+v will also be disabled sadly.
            alert('not allowed');
        }
        return false;
};​

どんな方法でも、私はそれを行う方法を知っているので、あなたに示します。

ここで右クリックを無効にします:

function clickIE() {if (document.all) {return false;}} 
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) { 
if (e.which==2||e.which==3) {return false;}}} 
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} 
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} 
document.oncontextmenu=new Function("return false") 
于 2012-07-11T13:39:33.450 に答える
0

alt + V + Cは、非常に奇妙な組み合わせです。次のコードは機能しますが、それは一種のハックです。

if (event.altKey) {
    if (event.keyCode == 67 && window.prevKey == 86)
        event.preventDefault();
    else if (event.keyCode == 86 && window.prevKey == 67)
        event.preventDefault();
    window.prevKey = event.keyCode
}
于 2012-07-11T13:51:03.877 に答える