Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript]Zablokowanie prawego przycisku myszy
Forum PHP.pl > Forum > Przedszkole
Istquai
Cześć, chciałbym zablokować prawy przycisk myszy na mojej stronie. W google znalazłem gotowy kod javascript ale po kliknieciu prawym przyciskiem wyskakuje okienko z wiadomoscią. A ja chciałbym poprostu zablokować ten prawy przycisk ale żeby nie wyskakiwały zadne okienka. Moglibyście napisać mi krótką formułke w javascripcie?
Szymciosek
Pokaż kod.
Ogólnie szukaj alert(...) i to wywal, bo on odpowiada za wyskakujące okienko.
mokry
A może kolega wkleiłby kawałek kodu, który użył na swojej stronie WWW?
Istquai
Teraz używam tego skryptu:

  1. <script language="JavaScript1.2">
  2. var msgpopup="Copy from blog are blocked ! ";
  3. function pmb(){
  4. if(alertVis == "1") alert(message);
  5. if(closeWin == "1") self.close();
  6. return false;
  7. }
  8. function IE() {
  9. if (event.button == "2" || event.button == "3"){pmb();}
  10. }
  11. function NS(e) {
  12. if (document.layers || (document.getElementById && !document.all)){
  13. if (e.which == "2" || e.which == "3"){ pmb();}
  14. }
  15. }
  16. document.onmousedown=IE;document.onmouseup=NS;document.oncontextmenu=new Function("alert(msgpopup);return false")
  17.  
mokry
Spróbuj tego:

[JAVASCRIPT] pobierz, plaintext
  1. var msgpopup="Copy from blog are blocked ! ";
  2. function pmb(){
  3. if(alertVis == "1") return false;
  4. if(closeWin == "1") self.close();
  5. return false;
  6. }
  7. function IE() {
  8. if (event.button == "2" || event.button == "3"){pmb();}
  9. }
  10. function NS(e) {
  11. if (document.layers || (document.getElementById && !document.all)){
  12. if (e.which == "2" || e.which == "3"){ pmb();}
  13. }
  14. }
  15. document.onmousedown=IE;document.onmouseup=NS;document.oncontextmenu=new Function("return false;")
  16.  
[JAVASCRIPT] pobierz, plaintext
Istquai
Dzięki wielkie smile.gif
kamil4u
Podajecie kod z zeszłego wieku...

[JAVASCRIPT] pobierz, plaintext
  1. function isRight(e){ e = e || window.event; if (e.which) return (e.which == 3); else if (e.button) return (e.button == 2); }
  2.  
  3. document.onclick = function(e){
  4. e = e || window.event;
  5. if( isRight(e) ){
  6. e.preventDefault();
  7. // Tu ew. własne operacje np:
  8. alert('prawy');
  9. }
  10. }
[JAVASCRIPT] pobierz, plaintext


Jak coś trzeba wyjaśnić to pytajcie.

--edit--
Ew. można dodać: https://developer.mozilla.org/en-US/docs/DO...w.oncontextmenu ,z tym, że powyższe rozwiązanie jest bardziej wszechstronne.
wNogachSpisz
plugin (nie ma już go w sieci):
[JAVASCRIPT] pobierz, plaintext
  1. /*!
  2.  * jQuery Right-Click Plugin
  3.  *
  4.  * Version 1.01
  5.  *
  6.  * Cory S.N. LaViska
  7.  * A Beautiful Site (http://abeautifulsite.net/)
  8.  * 20 December 2008
  9.  *
  10.  * Visit http://abeautifulsite.net/notebook/68 for more information
  11.  *
  12.  * License:
  13.  * This plugin is dual-licensed under the GNU General Public License and the MIT License
  14.  * and is copyright 2008 A Beautiful Site, LLC.
  15.  */
  16. if(jQuery){(function(){$.extend($.fn,{rightClick:function(a){$(this).each(function(){$(this).mousedown(function(c){var b=c;if($.browser.safari&&navigator.userAgent.indexOf("Mac")!=-1&&parseInt($.browser.version,10)<=525){if(b.button==2){a.call($(this),b);return false}else{return true}}else{$(this).mouseup(function(){$(this).unbind("mouseup");if(b.button==2){a.call($(this),b);return false}else{return true}})}});$(this)[0].oncontextmenu=function(){return false}});return $(this)},rightMouseDown:function(a){$(this).each(function(){$(this).mousedown(function(b){if(b.button==2){a.call($(this),b);return false}else{return true}});$(this)[0].oncontextmenu=function(){return false}});return $(this)},rightMouseUp:function(a){$(this).each(function(){$(this).mouseup(function(b){if(b.button==2){a.call($(this),b);return false}else{return true}});$(this)[0].oncontextmenu=function(){return false}});return $(this)},noContext:function(){$(this).each(function(){$(this)[0].oncontextmenu=function(){return false}});return $(this)}})})(jQuery)};
[JAVASCRIPT] pobierz, plaintext


użycie:
[JAVASCRIPT] pobierz, plaintext
  1. $('body').noContext();
  2. $('body').rightClick(function(){
  3. return false
  4. })
[JAVASCRIPT] pobierz, plaintext
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.