On copy prevention in HTML, part 1

Migrated from my old blog; originally posted 4/8/2007

Many web developers like to prevent their viewers from copying their text. While I do not approve of this, there are cases where it is appropriate.

The simplest way to achieve this is to use the IE only attribute UNSELECTABLE and the FireFox only css style -moz-user-select. Such HTML looks like this:

<DIV unselectable="on"
style="-moz-user-select:none;">
You can't select me.
</DIV>
You can't select me.

To make the HTML and CSS validate, one could do this in Javascript: Elem.unselectable = "on"; Elem.style.MozUserSelect = "none";

However, this method only works in IE and Firefox. In addition, in IE, it doesn't work very well, and if a user tries hard, he will end up selecting the text.

A slightly better way to do it is to handle the onselectstart event (for IE) and the onmousedown event (for everything else) and return false. This will prevent the browser from handling the events. This results in something like this:

<DIV
onselectstart="return false;"
onmousedown="return false;" >
You can't select me.
</DIV>
You can't select me.

The problem with these methods is that they do nothing to prevent a user from reading the HTML source. This is discussed in the next part.

4 comments:

It's nice that there are such blogs. Karina

It will be great idea for college students to read information from https://eduessayhelper.org/blog/sat-score. Here you can read how to get higher SAT score


ارخص شركة نقل عفش

ارخص شركة نقل عفش بالمدينة المنورة نقل عفش بالمدينة المنورة
ارخص شركة نقل عفش بمكة نقل عفش بمكة
شركة نقل عفش شركة نقل عفش

ارخص شركة نقل عفش بجدة نقل عفش بجدة
دينا نقل عفش جدة دينا نقل عفش بجدة



Hi there! I am extremely proud that our generation is so positive about innovative technologies, thank you for sharing great content. It is wonderful to watch this. To develop our talents, we need to learn something new every day of our life. In our time, learning has become both more difficult and easier, harder because curriculum is improving but the level of necessary knowledge is growing. It’s easier because the guys from https://bestresearchpaper.com/ continue to help students solve problems of varying complexity.

Post a Comment