|
I get more e-mail about this script than every other script on this site put together.
"How do I stop people from stealing my pictures?" So here it is. It works in
Netscape 4 and IE 4 and 5. But please read the part underneath before you put it on
your page, because I had it on mine for two months and then took it off.
(It's not running on this page, obviously. You'd hate me.)
THE SCRIPT
Goes in your <head>. Change the message to whatever you want.
<script language="JavaScript">
<!--
// No right click - Lorenzo's JavaScript Zone
var nrcMessage = "Sorry, right-click is turned off on this page.";
function nrcNetscape(e) {
if (e.which == 3) {
alert(nrcMessage);
return false;
}
return true;
}
function nrcIE() {
if (event.button == 2) {
alert(nrcMessage);
return false;
}
return true;
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = nrcNetscape;
} else if (document.all) {
document.onmousedown = nrcIE;
}
//-->
</script>
|
HOW IT WORKS
- Which browser is it? document.layers only exists in Netscape 4, and
document.all only exists in IE 4 and 5. So the script checks for each one to
figure out where it is. This trick is handy for lots of other scripts too.
- Netscape has to be told to listen for mouse clicks on the whole page, which is
what captureEvents does. Then when you click, it hands the function an
event, e, and e.which tells you the button: 1 is left, 3 is right.
- IE keeps its event in event instead, and it numbers the buttons
differently: event.button is 1 for left and 2 for right. Why are they different?
Nobody knows. Welcome to JavaScript.
- The alert box is what actually stops the menu. It grabs the mouse before the
right-click menu can open.
- IE 5 bonus: IE 5 has a special event just for the right-click menu. Add
document.oncontextmenu = nrcOff; plus a function
function nrcOff() { return false; } and the menu just quietly doesn't show up, no
box. Only IE 5 knows about it, though. Netscape and IE 4 skip right over it.
WHY I TOOK IT OFF MY OWN PAGE
I had it on the Zone when it first opened. Then my cousin Jenny came over, sat down at
our computer, opened the Temporary Internet Files folder, and showed me every single one
of my pictures sitting right there, already saved on the computer. She didn't even
right-click. I took the script off that night. Here's the truth about it:
- The pictures are already on their computer. Your browser saves everything it
shows you, in Temporary Internet Files in IE or the cache folder in Netscape, so the page
loads faster next time. Anybody can go in there and copy them out.
- They can turn JavaScript off. A few clicks in the options and your script is gone.
Right-click all you want.
- Print Screen still works. Press it, open Paint, paste. There's your picture.
- It doesn't hide your HTML. Everybody thinks it does. View, Page Source in Netscape
(or View, Source in IE) is right there at the top of the window. Right-click was just a
shortcut.
- It bugs everybody else. A lady named Linda e-mailed me when I still had it up.
She uses right-click for Back, and for opening links in a new window, and my box popped up
every single time she tried. She was nice about it, but she was right. The people it annoys
are your real visitors, not the picture thieves.
So basically it stops people who don't know much about computers from doing something
they probably weren't going to do anyway, and it annoys everybody. Your call. It's your page.
WHAT I'D DO INSTEAD
- Put your name right in the picture when you make it, in a corner, small. If
somebody takes it, your name goes with it.
- Just ask. A line at the bottom like "Please don't take my graphics without
asking" works on most people. The rest weren't going to listen to a script either.
- If it's your own photos or art and it really matters, only put small versions
on the Web. Nobody can steal the big one if it isn't there.
<< BACK TO THE ZONE
|