Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 25, 2012, 10:35:41 AM

Pages: [1]   Go Down
  Print  
Author Topic: Disableing right click on web site  (Read 443 times)
cwilliams
Trekkie
**
Offline Offline

Posts: 11


WWW
« on: October 29, 2002, 06:45:00 PM »

Does anyone know how to disable the right click function on a website? I'm sure there's a javascript out there somewhere?

Thanks!
Logged
stephan
Guest
« Reply #1 on: October 29, 2002, 08:22:00 PM »

Put this in the body section of your html page.

 
code:
 <script language="Javascript">

var mymessage = "Stop it!\nRight click is not allowed.";

  function disableRightClick(btnClick)
  {
    if (navigator.appName == "Netscape" && btnClick.which == 3) // check for netscape and right click
    {  
alert (mymessage);
      return false;
    }
    else if (navigator.appName =="Microsoft Internet Explorer" && event.button == 2)  // for IE and Right Click
    {
alert (mymessage);
      return false;
    }
  }
document.onmousedown = disableRightClick;
</script>
 

Logged
Johnny
MR-Disabled
Über Jedi
*
Offline Offline

Posts: 1914



« Reply #2 on: October 30, 2002, 06:39:00 AM »

As much as I despise "right click disable", I'll post this anyway.

You can add the following code in the body tag after: alink example: <body bgcolor="#FFFFFF" text="#000000" link="#0066CC" vlink="#006699" alink="#0033CC" oncontextmenu="return false" ondragstart="return false" onselectstart="return false">

That will disable right click, and also highlighting any text on the page.
 
 [ October 30, 2002, 02:48 PM: Message edited by: whoisthis ]
Logged

stephan
Guest
« Reply #3 on: October 30, 2002, 06:41:00 AM »

Thanks, that is just what I was looking for actually!
Logged
cwilliams
Trekkie
**
Offline Offline

Posts: 11


WWW
« Reply #4 on: October 30, 2002, 06:36:00 PM »

Ok,,thanks for the script. BTW I'm disabling right click on one page only for confidential reasons only. Thx!
Logged
stephan
Guest
« Reply #5 on: October 30, 2002, 07:47:00 PM »

Disabling right-click is not secure!

If you are putting confidential things in your html, that is a big problem.

Anyone can get round the right-click disabling, very easily!

Also, some methods do not work in all browsers, especially this one - "oncontextmenu="return false" ondragstart="return false" onselectstart="return false" - which will only work in Internet Explorer.
Logged
Brian
Jedi
*****
Offline Offline

Posts: 874


WWW
« Reply #6 on: November 01, 2002, 04:56:00 PM »

stephan's right about that one. there really is no purpose in disabling right click if it's for security. i'd look into more secure means of protection.

-Brian
Logged

BS
Spacescooter Operator
*****
Offline Offline

Posts: 32


WWW
« Reply #7 on: December 24, 2002, 03:43:00 AM »

i think my java code can grab source even if right click is disabled.  So I wouldnt put anything confidential like that.  Thats bad coding  "[Smile]"   I am sure people here can tell you ways to work around it.
Logged
stephan
Guest
« Reply #8 on: December 26, 2002, 10:37:00 PM »

Well, yeah, you can just visit the page with javascript disabled
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: