げんたろう's備忘録

セキュリティに関して思ったことをまとめます。

右クリック等マウスイベント禁止への対策

日常使っている歌詞のサイト等ではドラッグやコピー、右クリックが禁止されている場合が多い。そのような場合の対処方法として、chrome等に実装されているconsoleから特定のコマンドを入力することで回避する方法について記載する。

ページソースを以下のようにすることで右クリックを行うことができるようになる。

document.onmousedown = function(){ return true; };
document.onmouseup = function(){ return true; };
document.onclick = function(){ return true; };
document.oncontextmenu = function(){ return true; };
document.ondragstart = function(){ return true; };
document.onselectstart = function(){ return true; };
document.oncopy = function(){ return true; };
document.oncut = function(){ return true; };
document.onbeforecopy = function(){ return true; };
document.onbeforecut = function(){ return true; };