Right-click

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Right-click

Post by S_henry »

Can we make our page can't be right-clicked? I mean if we right-click at any pages, then nothing heppen. Anybody know?
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Code: Select all

<script language=JavaScript>
<!--

//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="Function Disabled!";

///////////////////////////////////
function clickIE4()&#123;
if (event.button==2)&#123;
alert(message);
return false;
&#125;
&#125;

function clickNS4(e)&#123;
if (document.layers||document.getElementById&&!document.all)&#123;
if (e.which==2||e.which==3)&#123;
alert(message);
return false;
&#125;
&#125;
&#125;

if (document.layers)&#123;
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
&#125;
else if (document.all&&!document.getElementById)&#123;
document.onmousedown=clickIE4;
&#125;

document.oncontextmenu=new Function("alert(message);return false")

// --> 
</script>

From http://www.dynamicdrive.com/dynamicindex9/noright.htm
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

And if you want to use a silent right click.

Code: Select all

<script language=JavaScript>
<!--

//Disable right click script III- By Renigade (renigade@mediaone.net)
//For full source code, visit http://www.dynamicdrive.com

var message="";
///////////////////////////////////
function clickIE() &#123;if (document.all) &#123;(message);return false;&#125;&#125;
function clickNS(e) &#123;if 
(document.layers||(document.getElementById&&!document.all)) &#123;
if (e.which==2||e.which==3) &#123;(message);return false;&#125;&#125;&#125;
if (document.layers) 
&#123;document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;&#125;
else&#123;document.onmouseup=clickNS;document.oncontextmenu=clickIE;&#125;

document.oncontextmenu=new Function("return false")
// --> 
</script>
From http://www.dynamicdrive.com/dynamicindex9/noright3.htm
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

This also seems to work, at least for IE.

<body oncontextmenu="return false">
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

microthick wrote:This also seems to work, at least for IE.

<body oncontextmenu="return false">
Whatever you do, do not use that, it disables a lot more than right clicking and becomes somewhat of an annoiyance.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

However do not expect it to be bulletproof. anybody who wants to rip youre code can do that.. if they persistant enough...
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

And of course it is.... ;)
User avatar
monkeyj
Forum Commoner
Posts: 82
Joined: Mon Dec 15, 2003 4:32 pm
Location: USA
Contact:

Post by monkeyj »

Hey personally.. I find anti-right clicking sites are annoying..
Don't do it.. o.o

I mean
If the person wants your image..
They can d/l it from the source... directly.. or w/e..
but.. Disabling right click is lame.. o.o


Just put SAMPLE over it..
but it is annoying o.o
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

monkeyj wrote:Hey personally.. I find anti-right clicking sites are annoying..
Don't do it.. o.o

I mean
If the person wants your image..
They can d/l it from the source... directly.. or w/e..
but.. Disabling right click is lame.. o.o


Just put SAMPLE over it..
but it is annoying o.o
Why? Right click provides no functions that a user would need to view a page or navigate... a user visiting a site dont need right click peroid unless they are up to no good, so as far as right click disabling being lame, thats just silly.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Good point Tim....
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post by uberpolak »

If you're trying to save an image, rather than hotlink it, right clicking makes it easier, not necessary for the job, but much easier. Plus, it's annoying if you hit the button by accident and a "Don't do that" alert box pops up.

I agree, anti-right-click nazis need to lighten up. <hippyvoice>The mouse has two buttons for a reason, man.</hippyvoice>
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

Why do you want to save a picture to your HD,
they are good at where they are, just like flowers :) lol ...
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post by uberpolak »

What I'm saying is, if you're going to use an image from elsewhere on your site (assuming of course this is kosher in a particular instance), it's much more considerate to save it for yourself, rather than use the original site's bandwidth.

Or if you have dial-up access, and you want to be able to come back to a particular picture, it's much easier than waiting for it to load all the time.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

the only valid reason i see for right click is when you download a MP3 or a file, I know I personally like the Right click ->Save Target As, but could easily go without.... and if the webmaster of the page Has a page that has file downloads, then implenting the right click disable would be strange, none the less..

Right click isnt needed peroid.
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post by uberpolak »

No, it's not needed, just makes life easier sometimes.
Post Reply