Skip to main content
Home Forums Disabling right click?
Disabling right click?
· Troubleshooting · 17 posts · Mar 23, 2005 — Apr 21, 2005 View original thread ↗
i hate how long the script is :( and searching for a way to disable rightclick but use the least about of lines

code:
<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="Yo! This is my site and my files \n Please ask the webmaster \n if you can have it";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

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

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

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

// -->
</script>




could i make it in the head of my html and php files do
code:
<script scr=disable.js></script>

and then have a js file with all the code to disable right click in it?
Why?
Quote:
Originally posted by jay3ld:
could i make it in the head of my html and php files do
code:
<script scr=disable.js></script>

and then have a js file with all the code to disable right click in it?

You try it and tell me whether or not you can do that. It's not as though sticking a line at the top of an HTML file is such an laborious process that it requires research beforehand.
i don't see the point in this.

if it's to protect images and stop people right-clicking to save, i can just view source, see the image paths, and then load'em up if i want to save them. if you wanted to be really arsey about it, you could use Flash in the way that Flickr does; except that they offer a link to the actual image, too. either way, there's nothing to stop someone screengrabbing the image . or running wget on the site and taking everything on your site.

if it's to view source, there's a menu option on every browser.

the point being: it's just extra work for the sake of it, and it makes you look a bit precious (in my opinion).

what's your particular reason for wanting to do this?
document.oncontextmenu = function(){return false;};

or the new Function way in your script. That'll work for most browsers you'll get coming to your site (well, I presume it'll work in IE, but I'm not going waste my time actually testing something like this )

But, as everyone else has said, why do you want to do this? It's incredibly simple to get round and just pisses the hell out of people who want to use the context menu for something else.

And anyway, there's nothing really wrong with the script you posted being that many lines - it's just browser checking for the people who haven't upgraded in the last 7+ years...

Oh yeah, and of course you can put that in an external JS file and just link it. It's good practice to do that for all scripts you're going to use teh web.
Quote:
Originally posted by Black Book:
I'm not going waste my time actually testing something

right there, that's your motto
Quote:
Originally posted by Phil Sherry:
right there, that's your motto


Shap u!

For that comment, I'll buy the first round and you can buy the rest
I've been screwing with this idea as a mental exercise. I saw someone create a script to do this on another forum, and I was thinking I could do it more thoroughly. The biggest problem I face with it is that I think the notion of restricting usability and disabling expected features on your site (That would be adding counter-intuitivity for lack of a better term) is a terrible one, but in learning javascript I thought it would be a fun project to tackle. So the big hump to get over is that this sort of script goes against everything that I believe in, but that does add an element of amusement at the same time.

I've managed to make a dreadful page from it, however. It's delightfully frustrating to use. It still needs some more work though. I'm convinced that with a little time and effort I can make the page even more difficult to use. I'm currently wanting to add another layer of un-usability to it, I figure that if I set the img src in the mark-up to blank (<img src="" alt="picture of whatever" />, I can parse the class attribute or the alt attribute or both to dynamically create the url of the image, and load it in. That would require the user to not only have to view source, but also poke around the script to find all of the pieces of the url. What's more is that I could set an attribute to a tag like the body tag, and use that as the path name to images that I wouldn't the user to steal.

I feel so dirty. But it's fun. But even still, it's hardly foolproof. The status bar in most browsers gives it all away, and the Activity Window in Safari provides one-click access to the image.

But it is a fun exercise, none the less. I
i do it 2 protect allot of my secret code. i do allot 2 protect it and doing this is just 1 more way to : censor: them off
Quote:
Originally Posted by jay3ld
i do it 2 protect allot of my secret code. i do allot 2 protect it and doing this is just 1 more way to : censor: them off

Still a waste of time.
Secret code? Now this I've got to see.
It's ROT-13, isn't it?
Do you have a link we could see?
Quote:
Originally Posted by Chuckit
It's ROT-13, isn't it?


EBG-13 vf gru orfgrfg rapelcgvba, rine!!

Takes me back, does that
Quote:
Originally Posted by Black Book
EBG-13 vf gru orfgrfg rapelcgvba, rine!!


Do you want some help removing that gag?
I think it'd be quite fun to have a dynamic .js file that document.writes your entire pag. For instance,

index.php
--------
code:


<script language="javascript" src="annoyingPageCreator.js?page=#PAGEID#"></script>




annoyingPageCreator.js
--------
PHP Code:
var line;

<?
php

/*
Not exactly sure if this is what we'd want, but who really cares?
*/
if($_SERVER['HTTP_REFERER'] == "index.php") {
    
    
$pageSource = getSource($page);
    
    
$pageSource = addslashes($pageSource);
    
    print(
"line = '" . $pageSource . "';");
    
}

?>
document.write(line);
mp.ls