DelphiFAQ Home Search:
General :: Programming :: JavaScript
Code snippets to add functionality to your HTML pages, preferably cross-browser.


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Disable text selection with the mouse


How can I disable text selection by mouse clicking or dragging of a text block?


You could disable any mouse-down event with code as shown below (to be put in an onload event. The downside of this is that nothing will work anymore, not even clicks on links.

Also know that a user still can click on the document and use 'Select All' from the Edit menu (or in Internet Explorer even use a shortcut Control+A), followed by 'Copy' from the menu.

There is simply no way to protect displayed content, you can only make it a bit more difficult.

// Internet Explorer:
 if (document.all)
   document.onselectstart =
     function () { return false; };
 // Netscape 4:
 if (document.layers) {
   document.onmousedown =
     function (evt) { return false; };
 // Netscape 6:
 document.onmousedown = function () { return false; };

Generated 12:01:35 on Oct 27, 2020