Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Zablokowanie prawego przycisku myszy
Istquai
post 1.01.2013, 22:33:31
Post #1





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 2.12.2012

Ostrzeżenie: (0%)
-----


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?
Go to the top of the page
+Quote Post
Szymciosek
post 1.01.2013, 22:35:10
Post #2





Grupa: Zarejestrowani
Postów: 1 168
Pomógł: 126
Dołączył: 5.02.2010
Skąd: Świdnica

Ostrzeżenie: (0%)
-----


Pokaż kod.
Ogólnie szukaj alert(...) i to wywal, bo on odpowiada za wyskakujące okienko.

Ten post edytował Szymciosek 1.01.2013, 22:35:41
Go to the top of the page
+Quote Post
mokry
post 1.01.2013, 22:35:21
Post #3





Grupa: Zarejestrowani
Postów: 374
Pomógł: 23
Dołączył: 3.06.2006
Skąd: Katowice

Ostrzeżenie: (0%)
-----


A może kolega wkleiłby kawałek kodu, który użył na swojej stronie WWW?


--------------------
Pomogłem? Podziękuj proszę klikając poniżej "POMÓGŁ" ;)
Go to the top of the page
+Quote Post
Istquai
post 1.01.2013, 23:05:29
Post #4





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 2.12.2012

Ostrzeżenie: (0%)
-----


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.  
Go to the top of the page
+Quote Post
mokry
post 1.01.2013, 23:32:02
Post #5





Grupa: Zarejestrowani
Postów: 374
Pomógł: 23
Dołączył: 3.06.2006
Skąd: Katowice

Ostrzeżenie: (0%)
-----


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


Ten post edytował mokry 1.01.2013, 23:40:18


--------------------
Pomogłem? Podziękuj proszę klikając poniżej "POMÓGŁ" ;)
Go to the top of the page
+Quote Post
Istquai
post 2.01.2013, 00:16:01
Post #6





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 2.12.2012

Ostrzeżenie: (0%)
-----


Dzięki wielkie smile.gif
Go to the top of the page
+Quote Post
kamil4u
post 2.01.2013, 13:55:33
Post #7





Grupa: Zarejestrowani
Postów: 2 350
Pomógł: 512
Dołączył: 4.01.2009
Skąd: Wrocław / Świdnica

Ostrzeżenie: (0%)
-----


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.

Ten post edytował kamil4u 2.01.2013, 14:00:11


--------------------
Go to the top of the page
+Quote Post
wNogachSpisz
post 3.01.2013, 14:52:24
Post #8





Grupa: Zarejestrowani
Postów: 1 233
Pomógł: 87
Dołączył: 6.03.2009

Ostrzeżenie: (40%)
XX---


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


Ten post edytował wNogachSpisz 3.01.2013, 14:53:59
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 12.05.2025 - 12:05