Is there a chance to disable these two things from my site? (View Source) and (Ctrl + C )
-
6Please don't down-vote this question just because you believe these things aren't worth doing. Maybe the poster realizes that a determined user will not be prevented from accessing the content of his site; maybe he is just interested in making it a little more difficult for the average user to do so, for whatever reason. – Avi Jun 24 '09 at 11:05
-
Thankx Avi How its done in Orkut. We all know that its done in Orkut but Question is how – Bhavi Jun 24 '09 at 12:44
-
@Bhavi just look at their code xD – fortran Jul 07 '09 at 17:25
10 Answers
This isn't possible. You could try to somehow obfuscate the code, but you need to send something to client, don't you? You could use AJAX calls to load your html. This way, the source that the browser will show could be almost empty. However, there is nothing you can do to prevent an experienced user from viewing everything you are sending to the client. In fact there are so many tools he/she can use to reconstruct the page that any technique you will fight hard to apply, will only delay him/her for a couple of minutes.
Regarding the Ctrl-C you could add javascript to block it, but it is useless, since the user can always disable javascript. In fact many users will find interception of right-click very annoying.
All these could have a meaning if you are building an intranet application or you can ship an integrated browser for users to view the application. With public html, I believe it isn't even worth trying. One solution would be to build your application with flash or another plug-in. This way you can encrypt everything you've sent to the client.

- 103,016
- 27
- 158
- 194
-
-
No, I mean making the code difficult to read. This is especially true for javascript code. For html you can try loading it with AJAX calls. This will make more difficult, but not impossible, to reconstruct the page. – kgiannakakis Jun 24 '09 at 10:46
-
-
-
Sure it is possible. You cannot prevent a sophisticated user from accessing the content, but you can make most browsers, executing JavaScript, prevent selecting text. See http://www.answers.com/topic/yellow-submarine-performed-by-various-artists for an example. – Avi Jun 24 '09 at 10:48
-
2var isnn,isie if(navigator.appName=='Microsoft Internet Explorer') //check the browser { isie=true } if(navigator.appName=='Netscape') { isnn=true } function right(e) //to trap right click button { if (isnn && (e.which == 3 || e.which == 2 )) return false; else if (isie && (event.button == 2 || event.button == 3)) { alert("Sorry, you do not have permission to right click on this page."); return false; } return true; } – Bhavi Jun 24 '09 at 10:49
-
1@Bhavi: You can't, simple as that. Whatever you're trying to hide should either be store somewhere else than in the HTML, or you should resign yourself to the fact that it's public. – mikek Jun 24 '09 at 10:50
-
7@Bhavi You seem to have managed to find some ugly (very ugly, it uses navigator.appName of all things) code that attempts to block the context menu. As previously mentioned, this isn't very effective. (It is very annoying though). You cannot stop people from accessing HTML/CSS/JS source code that is delivered to the browser (and it has to be delivered to the browser to work). Accept that fact, and move on. – Quentin Jun 24 '09 at 10:52
-
1No matter how hard you obfuscate the code, in the end you will need to have a meaningful DOM tree otherwise the browser won't render it - and once you have a DOM tree, Bugzilla or the Webkit Inspector shows everything. – Tamas Czinege Jun 24 '09 at 11:04
-
Firebug can also show you the DOM tree. It will even allow you to select a portion of the page and show you the corresponding DOM. – kgiannakakis Jun 24 '09 at 12:26
-
Well Is there something that we can apply on our CS file for a ASP.net page – Bhavi Jun 24 '09 at 12:42
It's possible to disable CTRL+U and CTRL+C. This may work:
shortcut = {
all_shortcuts: {},
add: function (e, t, n) {
var r = {
type: "keydown",
propagate: !1,
disable_in_input: !1,
target: document,
keycode: !1
};
if (n) for (var i in r) "undefined" == typeof n[i] && (n[i] = r[i]);
else n = r;
r = n.target, "string" == typeof n.target && (r = document.getElementById(n.target)), e = e.toLowerCase(), i = function (r) {
r = r || window.event;
if (n.disable_in_input) {
var i;
r.target ? i = r.target : r.srcElement && (i = r.srcElement), 3 == i.nodeType && (i = i.parentNode);
if ("INPUT" == i.tagName || "TEXTAREA" == i.tagName) return
}
r.keyCode ? code = r.keyCode : r.which && (code = r.which), i = String.fromCharCode(code).toLowerCase(), 188 == code && (i = ","), 190 == code && (i = ".");
var s = e.split("+"),
o = 0,
u = {
"`": "~",
1: "!",
2: "@",
3: "#",
4: "$",
5: "%",
6: "^",
7: "&",
8: "*",
9: "(",
0: ")",
"-": "_",
"=": "+",
";": ":",
"'": '"',
",": "<",
".": ">",
"/": "?",
"\\": "|"
}, f = {
esc: 27,
escape: 27,
tab: 9,
space: 32,
"return": 13,
enter: 13,
backspace: 8,
scrolllock: 145,
scroll_lock: 145,
scroll: 145,
capslock: 20,
caps_lock: 20,
caps: 20,
numlock: 144,
num_lock: 144,
num: 144,
pause: 19,
"break": 19,
insert: 45,
home: 36,
"delete": 46,
end: 35,
pageup: 33,
page_up: 33,
pu: 33,
pagedown: 34,
page_down: 34,
pd: 34,
left: 37,
up: 38,
right: 39,
down: 40,
f1: 112,
f2: 113,
f3: 114,
f4: 115,
f5: 116,
f6: 117,
f7: 118,
f8: 119,
f9: 120,
f10: 121,
f11: 122,
f12: 123
}, l = !1,
c = !1,
h = !1,
p = !1,
d = !1,
v = !1,
m = !1,
y = !1;
r.ctrlKey && (p = !0), r.shiftKey && (c = !0), r.altKey && (v = !0), r.metaKey && (y = !0);
for (var b = 0; k = s[b], b < s.length; b++) "ctrl" == k || "control" == k ? (o++, h = !0) : "shift" == k ? (o++, l = !0) : "alt" == k ? (o++, d = !0) : "meta" == k ? (o++, m = !0) : 1 < k.length ? f[k] == code && o++ : n.keycode ? n.keycode == code && o++ : i == k ? o++ : u[i] && r.shiftKey && (i = u[i], i == k && o++);
if (o == s.length && p == h && c == l && v == d && y == m && (t(r), !n.propagate)) return r.cancelBubble = !0, r.returnValue = !1, r.stopPropagation && (r.stopPropagation(), r.preventDefault()), !1
}, this.all_shortcuts[e] = {
callback: i,
target: r,
event: n.type
}, r.addEventListener ? r.addEventListener(n.type, i, !1) : r.attachEvent ? r.attachEvent("on" + n.type, i) : r["on" + n.type] = i
},
remove: function (e) {
var e = e.toLowerCase(),
t = this.all_shortcuts[e];
delete this.all_shortcuts[e];
if (t) {
var e = t.event,
n = t.target,
t = t.callback;
n.detachEvent ? n.detachEvent("on" + e, t) : n.removeEventListener ? n.removeEventListener(e, t, !1) : n["on" + e] = !1
}
}
},
shortcut.add("Ctrl+U",function(){
// Script to be executed when user press CTRL+U;This also disable and cancel the CTRL+U method
}),
shortcut.add("Ctrl+C",function(){
// Script to be executed when user press CTRL+C;This also disable and cancel the CTRL+C method
}),
For demo, you can visit my fiddle:
http://jsfiddle.net/dVSRM/
So the conclusion is it's possible to disable the CTRL+U and CTRL+C. But the high-grade plagiarism can know this and never uses the shortcut to view the source code. This tips can be for your reference if someone make a question about disabling the view source shortcut. But the CTRL+C is include in this script.
This is my script. Thank you. See you later!

- 51
- 1
- 1
It's pretty pointless trying to disable the 'view source' and 'ctrl-c' functionality, as anything you try will be easy to circumvent. You can use some JavaScript to stop the right-mouse button from displaying the context menu, but that's easy for the user to disable.
If it's JavaScript, you can use a JavaScript obfuscation program or compactor which will help to hide your code a bit.
Here's a couple to get you started.
http://www.javascriptobfuscator.com/
javascriptcompressor.com

- 1,489
- 13
- 20
There is no way to stop someone from reading the code you send to the browser. Even if you add browser tricks they could use an app that mimics a browser. The best thing to do is to move important code to the server, where they can't get at it.
Rather compete on other axes - usability, service, first mover advantage, etc than trying to stop someone from stealing your code.
Update: one thing you could do is use Google Web Toolkit, because then you'll be working in Java and your competitor/copier will spend their time deconstructing your Javascript.
What are you trying to protect? HTML/Javascript/images/server locations?

- 2,584
- 1
- 23
- 30
Send the pages as raster images (JPG, PNG, etc.) with area links instead of text xD

- 74,053
- 25
- 135
- 175
As others have said, there is no point to doing this, as well as the fact that it is impossible.
It's like a newspaper giving out newspapers, but without letting people take clippings. If they have to read it to know what it is, then can copy it.
Make the newspaper out of steel, they will just use laser to clip bits out, or take a photo.
Make the text invisible, no one can read it.

- 71,795
- 44
- 182
- 241
If you don't want users to view the code of your webpage then you should write your own web browser and define your own HTML protocol.
But when you create a client application and use SOAP/Web services to send data to those clients, then you will be able to keep the code hidden on anything the client sees. (They would need a debugger to "hack" your application.)
Of course, one way to distribute such an application would be by using Silverlight or Flash. It would still show up in browsers that have Flash or Silverlight enabled but they will not be able to see the code of anything inside the application.

- 25,901
- 20
- 83
- 149
-
1You don't even need a debugger to see the source of a web page loaded with ajax or web services : in Firefox, just do CTRL+a on the webpage, right click "View selection source", and voila ! – Fabien Ménager Jun 24 '09 at 11:09
-
+1 for originality. A little nitpicking: HTML is not a protocol - Usually the top level protocol for transferring web content is HTTP. – l0b0 Jun 24 '09 at 11:29
-
Fabien, my client would NOT be a website but a full-fledged application written in Delphi/WIN32 or in .NET. The Flash/Silverlight solution would be something in-between such a client application and a web page. – Wim ten Brink Jun 24 '09 at 11:57
It is impossible. But if you really want to avoid copying information, you can generate image with text on it. Of course, Google and other search engines will not index your site information. But sometimes it is the goal :-)

- 2,526
- 3
- 25
- 32
-
Be careful. This approach is usually incompatible with discrimination law (such as the DDA in the UK). – Quentin Jun 24 '09 at 10:54
-
-
Your goals of SEO but also content which cannot be read/copied by Humans are contradictory. – Josh Jun 24 '09 at 13:13
If you really don't want to give your code away there isn't much you can do.
Using flash or a java applet will make it a little more difficult, but even this can be decompiled.

- 11,707
- 6
- 46
- 71
The best you could do is to obfuscate your javascript. Any encryption will have to let the browser decrypt it. Catch-22.

- 2,988
- 24
- 19