Preventing Copy and Paste of Posts in Beautifulhugo

Applying copy-and-paste protection

* This page contains promotional content

Preventing copy and paste of posts

Referring to “テキストのドラッグ、画像のコピーを禁止して、記事をコピーさせない方法 ” (in Japanese), I disable text selection (dragging)

Note that this is applied for the Beautifulhugo theme, so adapt it as appropriate for other themes.

Adding the script

Add this inside the body tag

  • beautifulhugo/layouts/_default/baseof.html
<body onMouseDown="return false;" onSelectStart="return false">

Fixing the CSS

Add this to the css for body

  • beautifulhugo/static/css/main.css
user-select:none;
-webkit-user-select:none;
-ms-user-select: none;
-moz-user-select:none;
-khtml-user-select:none;
-webkit-user-drag:none;
-khtml-user-drag:none;

The point

In short, all you need to do is write the Javascript inside the body tag and apply the CSS to body in the CSS

See also