jQueryとContextMenuプラグイン-Operaで右クリック

最近、1つのプロジェクトの管理パネルに右クリックコンテキストメニューを実装するというタスクに直面しました。 この問題を解決するために、jQueryのプラグイン-contextMenuデモ )を見つけました。 私は例を見て、ダウンロードし、それをねじ込み、チェックし始めました。 IE-通常、FF-通常、Safari-通常、Opera-動作していません!

そして、問題は次のとおりです。
Operaでは、独自のコンテキストメニューを作成してマウスの右クリックを追跡することはできません。

解決策:
ご存じのとおり(または知らない)、OperaにはJavaScript設定(ツール-設定-詳細-コンテンツ-JavaScript設定)があり、「右マウスボタンの制御を許可する」というプロパティがあります。 クリックすると結果が得られます-JSは右クリックイベントをキャッチしてコンテキストメニューを表示しますが、その上に標準メニューが表示されます。 少しグーグルは彼の問題の解決策を見つけました:

// , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  1. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  2. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  3. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  4. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  5. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  6. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  7. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  8. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  9. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  10. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  11. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  12. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  13. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  14. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  15. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  16. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  17. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  18. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  19. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  20. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  21. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  22. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  23. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  24. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
  25. // , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .
// , if (navigator.appName.indexOf( "Opera" )!=-1){ // ( function (){ // , addEventListener( 'mousedown' , function (e){ // - if ( e && e.button == 2 ){ cancelMenu(e); return false ; } }, true ); var overrideButton; function cancelMenu(e){ if (!overrideButton){ var doc = e.target.ownerDocument; overrideButton = doc.createElement( 'input' ); overrideButton.type= 'button' ; (doc.body||doc.documentElement).appendChild(overrideButton); } overrideButton.style= 'position:absolute;top:' +(e.clientY-2)+ 'px;left:' + (e.clientX-2)+ 'px;width:5px;height:5px;opacity:0.01' ; } })( true , 1000 ); } * This source code was highlighted with Source Code Highlighter .


スクリプトは、標準のOperaコンテキストメニューを隠すボタンをページに作成します。 このスクリプトを管理パネルにねじ込んで、次のもの入手しました (Operaを参照)。 今、私はそれを喜んで使っています。

PS不必要な質問を避けるために、スクリプトは管理パネルでのみ使用されるため、右クリックトラッキングを有効にするようユーザーに求めることは怖くないと考えられていました。

Source: https://habr.com/ru/post/J45626/


All Articles