-1
4

6 回答 6

5

Render the code to an image and display that.

于 2012-08-13T22:10:27.677 回答
4

You could use this CSS to disable selection:

pre {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

It's hard to copy what you can't select.

However, as the comments have mentioned, there are ways around...

Here's a DEMO:

于 2012-08-13T22:13:15.583 回答
3

In combination with other techniques here, you could HTML-encode your content so that "view source" becomes inconvenient to use. For example:

​He​​​​​​​​​​​​​​​​​​​​​llo ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​World​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

renders as

Hello World

If your students write a program to decode the hex characters in the HTML-encoded version to plain ASCII, give them extra credit. :)

于 2012-08-13T22:29:22.863 回答
2

Not possible. You could display it inside a Flash movie, or as pre-rendered images sliced up into multiple smaller sections to prevent OCR, but then obvious workaround is to then take a screen capture and OCR that. In other words, it's easier to defeat any security system you put in place than it is to create the system in the first place

The attacker will ALWAYS have the upper hand, because you're handing them the keys to the vault by simply letting them view the protected content.

于 2012-08-13T22:08:04.260 回答
0

Could you insert invisible characters into the HTML code so if one copies it, it would be a pain to remove all those characters that would cause syntax errors but you wouldn't ever notice it unless you copied into a text editor. They would be randomized characters between every actual code character.

Visible code:

function foo()

Actual HTML:

f!u#n%c^t&i*o(n) (f@o$o%(^)&

Where each of the symbols are invisible unicode characters. I don't know how many of those there are but I tried the ZERO WIDTH NO-BREAK SPACE and it seemed to work. It would be an inconvenience. That's the best we can do, inconvenience, there is no foolproof way to stop somebody from copying the code.

To clarify, to anyone reading the page, they see the first line. To somebody who copied the text into a text editor, they'll either see squares or nothing but the code should not compile.

于 2012-08-13T22:23:09.763 回答
0

Another option, similar to images, but would take up a lot less space and bandwidth would be to grab draw the code on a canvas (possibly after getting it via ajax). Requires up-to-date browsers, and more programming, but would create clean text that cannot be easily copied.

于 2012-08-13T22:23:10.587 回答