Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

code to disable right click and view source

Posted on 2000-04-19
4
Medium Priority
?
16,006 Views
Last Modified: 2013-12-25
Previously submitted in Java but was told I should try a different category. Someone please advise if I have selected the wrong category. Thanks!

Could someone please forward me the code to disable view source and to also disable right click? I need this to work cross-browser 3.0 and up. Thanks.

(example exists at http://www.dotcomguy.com then click to watch him live. If you right click on the screen, a java window pops up thanking you for your support then you have to click ok to resume view. I believe the view source is disabled just by doing a javascript launched page and disabling tool bars but the right click thing has me stumped)
0
Comment
Question by:mediagirl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 18

Expert Comment

by:mgfranz
ID: 2731558
You can disable the right click in a page, but not the "View Source" button, so usnless yo are opening up a new window with buttons disabled this won't do much good.  But here is the code anyway;

<html>
<head><SCRIPT LANGUAGE="Javascript">
<!-- Hide from old browsers
function doNotSelect()
{
  return false;
}
document.onselectstart = doNotSelect;
// End Hide -->
</script>
</head>
<BODY OnLoad="doNotSelect()" onClick="doNotSelect()" onRightClick="doNotSelect()">
Test
</body>
</html>
0
 
LVL 2

Accepted Solution

by:
dog42 earned 1200 total points
ID: 2731679
Place this in your head tag:

<script language="javaScript">
function right(evnt){
 if (navigator.appName.toUpperCase().match(/NETSCAPE/) != null) {
  if (evnt.which >= 2){
   alert("We appreciate your support!");
   return false;
  }
 }else if (event.button>=2) alert("We appreciate your support.");
}

document.onmousedown = right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=right;
</script>

I got this from dotcomguy by using the contextmenu button on win95 keyboard.  To stop people doing this, add this to your body tag:

<body onContextMenu="alert('message');return false;">

Hope this helps,
Dog42

0
 
LVL 1

Author Comment

by:mediagirl
ID: 2732003
Thanks bud. I appreciate your preciseness and speed of an accurate response!
0
 

Expert Comment

by:kcoupland
ID: 11466295
Why would you want to disable right-click? Just think about how often the right-click (or left-click - lefties) is used.

If the code (JavaScript mostly) or images are to be protected then put in some copyright notices. Disabling right click I think is unprofessional and a sign you don't trust your visitors or clients.

If you want to protect something that badly, why have it on the web?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question